Repository navigation
fix(stl/net): OOM + concurrency hardening from the #3588 crash hunt - #3589
Conversation
Hardening batch from root-causing the classic-ESP32 crash under WiFi + HTTP-server + client traffic (#3588). The exact corrupter is still open (see issue for the full forensic record); every change here is independently correct and bench/host verified. - StringHolder: allocation failure now degrades to a coherent empty state instead of UB (writes through null; realloc leaked the old buffer and left null mData with a stale capacity). WiFi + server pushes classic ESP32 under 20 KB free where fl::malloc genuinely returns null. - make_shared / make_shared_with_deleter / make_shared_array: null control block or object (embedded new returns null with -fno-exceptions) now returns an empty shared_ptr instead of placement- constructing at an offset from null. - SlabAllocator (backs fl::map/set/multi_map/multi_set via allocator_slab): the static per-type instance is shared across FreeRTOS tasks (e.g. esp_http_server building Request/Response header maps while the main loop mutates its own) with zero synchronization. Added fl::detail::slab_mutex (FreeRTOS mutex on ESP32, atomic spinlock on host, no-op on single-threaded MCUs — the full fl/stl/mutex.h chain can't be used at the allocator layer without an include cycle) and guarded allocate/deallocate/cleanup. - asio http Server (ESP32): raise the esp_http_server task stack from the 4 KB IDF default to 8 KB — route handlers execute ON that task and run full fl::json/string/Response machinery. - AutoResearchNet: HTTP client timeout 5 s → 2 s + watchdog feed between blocking esp_http_client_perform() calls (single-core ESP32-C6 hit a tick-hook WDT panic_abort mid-test); server route handlers now format responses with fl::snprintf instead of building fl::json on the httpd task (defensive pending the #3588 root cause). - tests/fl/stl/json_cross_thread.cpp: cross-thread fl::json + map/string stress mirroring the device workload (ASAN-clean on host — the remaining corruption needs ESP32-specific machinery). Bench: C6 no longer WDT-panics during runNetClientTest; WROOM crash under concurrent traffic persists and stays open in #3588. Host: 347/347, lint clean. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughChanges harden ESP32 concurrency and memory-safety paths: AutoResearch examples avoid fl::json in HTTP handlers, reduce client timeout, add watchdog feeds, and expose a heapCheck RPC; a new slab_mutex synchronizes SlabAllocator; HTTPD stack size is increased; StringHolder and shared_ptr factories gain null-allocation handling; a cross-thread JSON test is added. ChangesAutoResearch Example Hardening
STL Synchronization and Allocation Safety
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Thread as Responder Thread
participant Handler1 as Handler Thread 1
participant Handler2 as Handler Thread 2
participant Json as fl::json/fl::map
participant Main as Test Main Loop
Main->>Thread: start responder loop
Main->>Handler1: start handler loop
Main->>Handler2: start handler loop
loop until counters reach 2000
Thread->>Json: build & serialize RPC response
Handler1->>Json: build headers/query map, serialize body
Handler2->>Json: build headers/query map, serialize body
Thread-->>Main: increment iteration counter
Handler1-->>Main: increment iteration counter
Handler2-->>Main: increment iteration counter
end
Main->>Thread: signal stop
Main->>Handler1: signal stop
Main->>Handler2: signal stop
Main->>Main: join threads and check counters
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Hardening batch from root-causing the classic-ESP32 crash under WiFi + HTTP server + client traffic (#3588). The exact corrupter is still open (full forensic record on the issue); every change here is independently correct and verified.
Library fixes
fl::mallocgenuinely returns null;grow()also leaked the old buffer and left a nullmDatawith stale capacity).make_sharedfamily null-safety: embeddednewreturns null with-fno-exceptions; the factories placement-constructed at an offset from null. Now return an emptyshared_ptr.fl::map/set/multi_map/multi_setis shared across FreeRTOS tasks (esp_http_server builds Request/Response header maps on its own task) with zero synchronization. Newfl::detail::slab_mutex(FreeRTOS mutex on ESP32 / atomic spinlock on host / no-op on single-threaded MCUs) guards allocate/deallocate/cleanup. The fullfl/stl/mutex.hchain can't be used at the allocator layer (include cycle).Bench fixes (AutoResearch)
panic_abortduringrunNetClientTest(single-core starvation, decoded from the RISC-V crash regs).fl::snprintfinstead of buildingfl::jsonon the httpd task (defensive pending Classic ESP32: heap corruption crash (LoadProhibited, garbage pointer) when AutoResearch HTTP server + client traffic runs alongside RPC response building #3588 root cause).Regression net
tests/fl/stl/json_cross_thread.cpp: cross-thread fl::json + map/string stress mirroring the device workload. ASAN-clean on host — the remaining corruption needs ESP32-specific machinery (documented on the issue).Host: 347/347; lint clean; esp32dev/esp32c6 compile clean. C6 traffic loop now survives; the WROOM crash under concurrent traffic remains open in #3588.
Refs #3588, #3576.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests