Updater::begin picks the 4 KB buffer by total free heap, and does not fall back to 256 B when the allocation fails
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- cpp
- Domínio
- embedded-iot
Direção de pesquisa
Leia cores/esp8266/Updater.cpp perto de UpdaterClass::begin() e _writeBuffer() e, em seguida, confira o template de stream em Updater.h para entender como o tamanho do buffer é usado. Verifique se é possível selecionar um buffer menor quando uma alocação de 4 KB falha e se a apagagem de setores continua funcionando com gravações de 256 bytes. O trabalho estará concluído quando begin() puder recorrer ao buffer menor em heaps fragmentados sem alterar o comportamento da atualização.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
What happens
UpdaterClass::begin() chooses its write buffer size from the total free heap:
// cores/esp8266/Updater.cpp, 3.1.2 lines 172-181 (same on master, lines 174-183)
if (ESP.getFreeHeap() > 2 * FLASH_SECTOR_SIZE) {
_bufferSize = FLASH_SECTOR_SIZE;
} else {
_bufferSize = 256;
}
_buffer = new (std::nothrow) uint8_t[_bufferSize];
if (!_buffer) {
_setError(UPDATE_ERROR_OOM);
_reset(false);
return false;
}
Total free heap says nothing about the largest free block. On a fragmented heap the check can pass while a 4096 byte block does not exist. Then new fails and begin() returns false with UPDATE_ERROR_OOM. The 256 byte buffer is never tried.
What I measured
- Core 3.1.2, ESP8266 (GeekMagic SmallTV-Ultra).
ESP.getFreeHeap()= 19.6 KB.ESP.getMaxFreeBlockSize()= 3,888 bytes.
What I did not measure
I did not run the upload in this state. I restarted the device first. That the upload would be refused with UPDATE_ERROR_OOM comes from reading the code above. 19.6 KB is more than 8192, so the 4 KB branch is taken. A 4096 byte allocation cannot fit in a 3,888 byte block.
Why a smaller buffer should be safe
_bufferSize is private and is only used inside Updater.cpp and the Updater.h stream template. The 256 byte case already exists for low free heap (commit 01e1c586, "Updater: if low on heap memory, use smaller write buffer"). _writeBuffer() erases a sector when _currentAddress % FLASH_SECTOR_SIZE == 0, which still works with 256 byte writes.
Proposed small change (sketch, untested)
- if (ESP.getFreeHeap() > 2 * FLASH_SECTOR_SIZE) {
+ if (ESP.getMaxFreeBlockSize() >= 2 * FLASH_SECTOR_SIZE) {
_bufferSize = FLASH_SECTOR_SIZE;
} else {
_bufferSize = 256;
}
_buffer = new (std::nothrow) uint8_t[_bufferSize];
+ if (!_buffer && _bufferSize > 256) {
+ _bufferSize = 256;
+ _buffer = new (std::nothrow) uint8_t[_bufferSize];
+ }
if (!_buffer) {
The first part picks by largest block. The second part is a safety net if the allocation still fails. Either part alone would already fix the case above. I can prepare a PR if this direction is fine.
- Linguagem predominante
- C++
- Estrelas
- 16.7k
- Forks
- 13k
- Merge médio
- 1d 2h
- PRs com merge (30d)
- 7
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de esp8266/Arduino
-
Typo in Scan Class DocumentationTalvez já em andamento @MukundaKatta assumiu há 207 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
esp8266/Arduino#9203 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 65/100
esp8266/Arduino#9324 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 42/100
Mantenedores costumam responder em até 1 dia
Todas as issues de esp8266/Arduino
Issues semelhantes
-
status:needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
PX4/PX4-Autopilot#29698 ·
Mantenedores costumam responder em até 1 dia
-
go perft exits when EvalFile is unavailableTalvez já em andamento @Muawiya-contact assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
official-stockfish/Stockfish#7292 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
arvidn/libtorrent#9149 ·
Mantenedores costumam responder em até 1 dia
-
Upstream report: MSVC rejects a designated initializer in a dependent template argument (C2131)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
rhalbersma/tabula#72 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia