Files
firmware/src/mesh/http
Ben Meadors 48699a7a48 fix(http): keep reaping open TLS connections under low heap so the heap can recover (#11539)
* fix(http): keep reaping open TLS connections under low heap so the heap can recover

Once free heap dropped below MIN_HEAP_FOR_SSL (40 KB) with HTTPS connections
open, the node's heap never came back and every later HTTPS or TCP-API
connection failed until a reset - node alive, on WiFi, unusable.

handleWebResponse() skipped secureServer->loop() entirely under low heap so no
new TLS handshake would be attempted on a heap that can't hold its context.
But HTTPServer::loop() is the only place already-accepted connections are
serviced and reaped: its first pass calls ->loop() on each open one (where the
20 s idle timeout and the SSL close-notify state machine run) and deletes the
closed ones. Skipping the whole loop froze the up-to-MAX_HTTPS_CONNECTIONS TLS
sessions already open. Never looped, they never timed out, their mbedTLS
contexts and pbufs were never freed, so free heap never climbed back over
40 KB, so the loop was skipped forever. The guard's own precondition was what
kept it from clearing.

Split the two halves. Under low heap keep driving and reaping the connections
we already hold, and only skip the accept. HTTPServer keeps its connection
table protected, so a thin MeshHTTPSServer subclass exposes
serviceExistingConnections(), the first half of HTTPServer::loop() verbatim.
Log line reworded to say what now happens: not accepting, not skipping.

Verified on a Heltec V3 (Endor AP) against a control build with #11537 (so the
node survives the squeeze instead of aborting first):

- Recipe: held sockets on 80/4403 + pending TLS, 100 s of HTTPS pokes, repeat.
  Control: Low heap pins at 6-17 KB, HTTPS dead, and 3 min after all pressure
  is released heap is still ~12 KB with Low heap firing every 30 s - permanent
  until reset. Fix: never dips under 40 KB, both pressure rounds 3/3, 65 KB
  after.
- Branch driven deliberately (verify-only heap hog pinning free heap at ~28 KB
  with a real idle TLS session held open): under the guard the fix logs
  open=1 -> reaped=1 at the 20 s idle timeout, and heap goes 26 -> 65 KB
  before the hog is even released. On the control logic that session stays
  frozen for the whole window.

Fixes #11538.

* fix(http): trim the low-heap comments to the two-line guideline

The mechanism is in the commit message and PR; the source keeps the one-line
why. No code change. (CodeRabbit)
2026-08-18 20:38:20 +00:00
..
2026-07-20 11:55:17 +02:00
2026-07-20 11:55:17 +02:00
2026-07-20 11:55:17 +02:00