Skip to content

fix(net): marshal esp_http_server route handlers onto the main task (#3588) + Xtensa link hotfix - #3597

Merged
zackees merged 1 commit into
masterfrom
fix/httpd-main-task-marshal-3588
Jul 2, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/httpd-main-task-marshal-3588

Conversation

@zackees

@zackees zackees commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Main-task marshaling (#3588 hardening)

Route handlers used to execute ON the esp_http_server task, running full fl:: machinery concurrently with the main loop. Now: the httpd task extracts plain-C request data, queues it, and blocks on a semaphore; the main task (via the existing task::Executor pump) runs the fl:: handler and returns a heap Response that the httpd task serializes with IDF C APIs. No fl:: object is constructed or mutated off the main task. Busy main loop → clean 5xx instead of cross-task execution.

Verified over the air (WROOM AP ⇄ C6 client): GET /ping 200 through the marshaled path.

Honest status: the #3588 corruption still reproduces even fully marshaled — eliminating the last fl-cross-task theory. New per-task stack watermarks (heapCheck tasks field) show all tasks healthy under traffic; RX ISR does no allocation; heap intact seconds before the crash. Next step documented on the issue: IDF-source build with comprehensive heap poisoning.

Hotfix

#3596's pre-filter ISR telemetry broke the classic-ESP32 link (l32r: literal placed after use in the IRAM rxDoneCallback) — telemetry writes now RISC-V-only. (Lesson: admin-merge + Xtensa IRAM = compile esp32dev before merging ISR-adjacent changes.)

Host: 347/347; lint clean; esp32dev/c6/s3 compile clean.

Refs #3588.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added optional task stack headroom details to heap check responses when tracing is enabled.
    • Improved request handling on ESP32 so web routes are processed more reliably on the main execution context.
  • Bug Fixes

    • Fixed ESP32 HTTP handling to reduce crashes and timeouts during request processing.
    • Limited certain telemetry updates to the supported architecture for more consistent behavior.

…3588)

Route handlers used to execute ON the esp_http_server FreeRTOS task,
running full fl::json/string/Response machinery concurrently with the
main loop's fl:: churn. Requests are now marshaled: the httpd task
extracts plain-C request data (method/uri/body buffers only), queues
it, and blocks on a semaphore; the main task — via the existing
task::Executor pump — runs the fl:: handler and hands back a
heap-allocated Response the httpd task then serializes with IDF C
APIs. No fl:: object is constructed or mutated off the main task.
When the main loop is busy (e.g. a long bench test), requests get a
clean 5xx instead of cross-task execution.

Verified over the air (WROOM AP + C6 client): GET /ping 200 through
the marshaled path. The #3588 corruption itself STILL reproduces even
with handlers fully marshaled — which eliminates the last
fl-object-cross-task theory; per-task stack watermarks (new heapCheck
"tasks" field) show every task healthy under traffic, the RX ISR does
no allocation, and heap integrity is intact seconds before the crash.
Full record on the issue; next step is an IDF-source build with
comprehensive heap poisoning.

Also:
- HOTFIX: #3596's pre-filter ISR telemetry broke the classic-ESP32
  link ("l32r: literal placed after use" in the IRAM rxDoneCallback);
  the telemetry writes are now RISC-V-only.
- heapCheck RPC reports per-task stack high-water marks.

Host: 347/347, lint clean; esp32dev/c6/s3 compile clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c8231f1a-fa11-46a1-ae30-38e1148ebfd5

📥 Commits

Reviewing files that changed from the base of the PR and between cc6a7c2 and f739bb3.

📒 Files selected for processing (3)
  • examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp
  • src/fl/stl/asio/http/server.cpp.hpp
  • src/platforms/esp/32/drivers/rmt_rx/rmt_rx_5/rmt_rx_channel_5.cpp.hpp

📝 Walkthrough

Walkthrough

This PR adds per-task stack headroom reporting to the AutoResearch heapCheck RPC, refactors the ESP32 asio HTTP server to marshal requests from the esp_http_server task to the main task via a queue/semaphore, and gates RMT RX channel 5 bench telemetry writes to RISC-V builds only.

Changes

ESP32 HTTP Server Request Marshaling

Layer / File(s) Summary
Pending request queue and async runner
src/fl/stl/asio/http/server.cpp.hpp
Adds EspPendingRequest, a global FreeRTOS queue, and a ServerAsyncRunner that drains the queue and runs RouteHandlers on the main task.
handle_esp_request extraction and response send
src/fl/stl/asio/http/server.cpp.hpp
Rewrites handle_esp_request() to extract plain-C request data on the HTTP task, enqueue it, wait via semaphore, then send the response and free buffers.
Server start/stop lifecycle updates
src/fl/stl/asio/http/server.cpp.hpp
start() creates the request queue and registers the runner; stop() stops httpd first, drains queued requests, then unregisters/resets the runner.

Diagnostics and platform-specific instrumentation

Layer / File(s) Summary
heapCheck RPC task stack headroom reporting
examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp
When configUSE_TRACE_FACILITY is enabled, queries task system state and adds a tasks JSON array with stack high-water marks to the RPC response.
RMT RX bench telemetry guarded for RISC-V
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_5/rmt_rx_channel_5.cpp.hpp
Wraps bench telemetry writes to g_rmtrx_cb_raw_symbols/g_rmtrx_cb_first_raw in an #if defined(__riscv) guard.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant HttpTask as esp_http_server task
  participant Queue as Request Queue
  participant MainTask as Main Task Runner
  participant Handler as RouteHandler

  Client->>HttpTask: HTTP request
  HttpTask->>HttpTask: extract method/URI/body
  HttpTask->>Queue: enqueue EspPendingRequest
  HttpTask->>HttpTask: wait on semaphore
  MainTask->>Queue: dequeue request
  MainTask->>Handler: construct Request, invoke handler
  Handler-->>MainTask: Response*
  MainTask-->>HttpTask: signal semaphore
  HttpTask->>Client: send HTTP response
Loading

Possibly related PRs

  • FastLED/FastLED#3589: Both PRs modify the ESP32 heapCheck RPC handler in examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/httpd-main-task-marshal-3588

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant