fix(network): stream WiFi API responses to prevent heap exhaustion - #10
Closed
meimeiesther wants to merge 23 commits into
Closed
fix(network): stream WiFi API responses to prevent heap exhaustion#10meimeiesther wants to merge 23 commits into
meimeiesther wants to merge 23 commits into
Conversation
Integrates the SD-card firmware update flow originally contributed by @donutboyy in aBER0724#3, with conflicts resolved against current `master`. Includes follow-up fixes for SDK pointer preservation, dark redrive handling, PlatformIO/CJK font generation settings, OTA installer stack usage, render-path string allocation, formatting, and cppcheck. Verified with: - `pio run` - `bin/clang-format-fix` - `pio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high` Credit to @donutboyy for the original SD firmware update contribution.
…update fix: Fix OTA update memory pressure
feat: add SD recovery firmware
- EpdFontData.h: add glyphMissHandler + glyphMissCtx for SD font on-demand loading - EpdFontFamily.h: new STRIKETHROUGH/SUP/SUB style bits (bitmask-compatible) - EpdFont.cpp: getGlyph falls back to glyphMissHandler when codepoint not in interval table - EpdFont.h: minor upstream alignment - FontDecompressor.h/.cpp: ligature prewarming - SdCardFont.h/.cpp: core SD card font data types (compiles standalone) - Retained: fork all.h (OpenDyslexic includes) Deferred: SdCardFontManager/Registry (need GfxRenderer API changes) Build: SUCCESS, RAM: 31.9%, Flash: 87.8%
- GfxRenderer.h: upstream SdCardFont/BiDi/strip/region cache APIs + fork dark mode fields - FontCacheManager: upstream constructor with SdCardFonts param - Bitmap.h/cpp: upstream HalFile migration - GfxRenderer.cpp: updated signatures to match header (BidiBaseDir default param) Build: SUCCESS, RAM: 31.9%, Flash: 88.0%
Replace dynamic String concatenation in handleWifiScan and handleWifiList with incremental chunked HTTP streaming (sendContent) to avoid heap fragmentation under low-memory conditions. Under the prior code, building a full JSON response string via String += on the heap could exhaust contiguous heap space needed by the WiFi driver's TX queue, triggering an abort() in lmacRetryTxFrame. Changes: - handleWifiScan: stream each network entry individually; increase buf from 256 to 320 bytes; add overflow guard to skip malformed entries - handleWifiList: stream each credential individually; use appendEscapedJsonString into a stack buffer; increase escapedSsid from 128 to 256 bytes to safely cover worst-case SSID escaping Root cause confirmed via addr2line decoding of crash report stack trace.
aBER0724
force-pushed
the
master
branch
3 times, most recently
from
September 2, 2026 09:02
a7193f3 to
ae32abf
Compare
Owner
|
Integrated the focused Wi-Fi response streaming fix locally on current master, then strengthened it to use watchdog-safe nonblocking chunk writes and corrected overflow handling so skipped entries cannot produce malformed JSON. Added a focused regression test. Verification completed before closing:
Integrated by master commits 23f0cf2 and e45d82b. The remaining historical changes on this branch are stale or already superseded, so this PR is now closed as integrated/superseded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stream WiFi API responses to prevent heap exhaustion on low-memory devices.
Problem
Under the prior implementation,
handleWifiScanandhandleWifiListbuilt their full JSON response strings using repeatedString +=concatenation on the heap. On the ESP32-C3, this can exhaust contiguous heap space needed by the WiFi driver's TX queue, triggering anabort()inlmacRetryTxFrame.Root cause was confirmed via
addr2linedecoding of a crash report stack trace.Changes
src/network/CrossPointWebServer.cpphandleWifiScan: stream each network entry individually usingsendContentinstead of concatenating into a singleString; increasebuffrom 256 → 320 bytes; add overflow guard to skip malformed entrieshandleWifiList: stream each credential individually; useappendEscapedJsonStringinto a stack buffer; increaseescapedSsidfrom 128 → 256 bytes to safely cover worst-case SSID escapingTesting
Verified fix resolves the crash on device by reproducing the heap-exhaustion condition (scanning in a WiFi-dense environment under reader load) and confirming clean operation post-patch.