Skip to content

ESP32: resume HTTP TCP writes without blocking the main loop - #2

Draft
blb4github wants to merge 1 commit into
pr/upstream-base-20261023from
pr/resumable-http-tx
Draft

blb4github wants to merge 1 commit into
pr/upstream-base-20261023from
pr/resumable-http-tx

Conversation

@blb4github

@blb4github blb4github commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Problem

Slow, intermittent, or disconnected browser clients could make synchronous ESP32 HTTP socket writes hold the HeishaMon main loop for seconds, delaying heat-pump control, rules, and MQTT processing.

Solution

  • Stage outgoing HTTP bytes per client so short/nonblocking TCP writes can be resumed on later main-loop iterations.
  • Bound each ESP32 HTTP TX attempt (MSG_DONTWAIT) and cap per-loop flushing, without changing the maximum of five web clients.
  • Limit each client to a 4 kB staged buffer and close stalled clients after 5 seconds without progress.
  • Preserve HTTP sendlist/chunk ordering; free staged buffers on client reset.
  • Remove experimental DIAG WEB timing output while retaining actual queue/socket/stall error logs.

Validation

  • Experimental ESP32-S3 firmware tested for ~15 h 23 min under intermittent VPN browser traffic: 853 resumed TCP writes, 44 stalled-client closures, 13 socket errors, no observed long DIAG WEB loop delays, overflows, or reboots, with ~180–195 kB heap.
  • Subsequent LAN-oriented log showed stable operation, though QNAP Browser Station was not persistently connected; not a continuous LAN stress run.
  • Isolated ESP8266/ESP32 compile checks have passed after diagnostic cleanup.
  • The final diagnostics-cleaned version has not yet had a separate long-duration hardware regression test.

Scope

Changes only HeishaMon/src/common/webserver.cpp and .h. Configurable GPIO is proposed independently.

Stage and resume partial HTTP TCP sends across main-loop iterations using bounded non-blocking socket operations; handle TX stalls and cleanup client buffers. Preserve maximum client count and exclude temporary diagnostic timing logs.
@blb4github
blb4github force-pushed the pr/resumable-http-tx branch from afdf958 to f6c6bac Compare October 24, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant