Repository navigation
fix(net): stop abandoning requests the peer is still serving - #4231
Conversation
The RP HTTP client gave each request 2000 ms. The peer's server allows
itself 5000 ms for the same request, so the client was giving up on work
the server was still legitimately doing.
The peer does not answer from its network task. On ESP, handle_esp_request()
queues the request to the sketch's main loop -- ServerAsyncRunner, pumped by
task::Executor -- and blocks up to 5000 ms on a semaphore waiting for it.
Nothing is written until that completes, so response latency is bounded by
the peer's loop cadence rather than by transmission. Measured on the bench,
4-to-55-byte static responses have a median of 552 ms and a p90 of 890 ms.
Evidence that the 2000 ms budget was the fault, not the peer:
- 241 cycles at 2000 ms produced 4 hard failures, every one with
elapsed_ms exactly 2000, the socket still open, and body_read 0 --
the client timing out, not the peer closing or resetting.
- 215 cycles at the larger budget produced 0, and five requests took
2706, 2734, 2961, 3108 and 3586 ms and completed correctly. Each of
those would have failed under 2000 ms.
- The maximum observed, 3586 ms, sits under the server's own 5000 ms
budget, as the mechanism predicts.
Uses kRpPeerMaxRequestMs so both sides of the fixture agree on how long a
request may take, instead of the client being stricter than the server.
Verified: bash compile rp2350 --examples AutoResearch succeeds.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
|
Warning Review limit reachedNext included review available in 6 minutes. View limit detailsLimit details: You’ve used all 8 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe RP2350W HTTP request test now starts its timing budget after sending the request body. It uses the 10-second peer request limit for response reads instead of a fixed 2-second deadline. ChangesRP2350W HTTP request timing
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to RP2350W HTTP requests can now wait for the peer’s full request budget rather than failing after two seconds while processing continues. No current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 |
|
Went I have not resolved it. The root conflict is on #4222 — #4220's deadline-reserve rewrite of the join loop against #4222's retry rewrite of the same loop — and combining them is new control flow rather than a merge, on a PR whose value is that it was validated on hardware I cannot re-run. These four may rebase cleanly once #4222 is resolved, since the conflict is largely downstream of that same region. Worth doing that one first and re-checking the rest before treating them as separate problems. |
Rebased onto master's stall-based timing from #4221, which changed the shape of this fix but not the need for it. #4221 replaced one flat deadline with a stall timer refreshed by every byte that arrives, plus an absolute ceiling. That is the right structure, and it fixes a peer that dribbles bytes. It does not fix this failure, because the ESP peer sends *nothing at all* until its main loop services the request -- handle_esp_request() queues to ServerAsyncRunner and blocks up to 5000 ms -- so there are no early bytes to refresh the stall timer. last_progress_ms is still sitting at the exchange start, and the first-byte wait therefore expires after kRpHttpClientStallMs exactly as the flat deadline did. With stall=2000 and ceiling=4000, both values are below the peer's own 5000 ms budget, so the client still abandons requests the server is still serving. Measured: 4 hard failures in 241 cycles, each with the socket open, zero bytes read, and elapsed equal to the client budget; and with a larger budget, 0 in 215 cycles with five requests completing correctly at 2706, 2734, 2961, 3108 and 3586 ms. Every one of those five would fail at 2000 ms. Stall becomes 6000 ms, above the peer's 5000 ms ceiling, so silence is only called a stall once the peer has provably given up. The exchange ceiling becomes kRpPeerMaxRequestMs, so both sides of the fixture agree on how long one request may take. The maximum observed, 3586 ms, sits inside both. Verified: bash compile rp2350 --examples AutoResearch succeeds. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
…#4372) `--net-peer` failed intermittently -- about two runs in five, on master and on unrelated branches alike -- with the RP's HTTP server taking complete headers and then none of a 4096-byte body: POST /echo 4096-byte FNV-1a -> 408, received_bytes: 0 {'lastTimeoutWasStall': True, 'lastTimeoutElapsedMs': 2006, 'lastTimeoutBodyLength': 0, 'lastTimeoutExpectedBody': 4096, 'lastTimeoutHeadersComplete': True} 2006 ms against a 2000 ms budget: the peer missed by six milliseconds. `kRpHttpClientStallMs` was raised 2000 -> 6000 in #4231 after five requests at 2706-3586 ms were shown to complete correctly, all under the peer's own 5000 ms handler ceiling. `kRpPeerStallMs` was left at 2000 so a dead connection would be reaped quickly. That treats the budget as a property of which side we are, when it is a property of the peer: the C6 services a request from its sketch main loop and blocks up to 5000 ms doing it, so a gap over 2000 ms is ordinary in either direction. The failure above is that same distribution seen from the other end. Set to 6000 to match the client rather than to clear the observed 2006 ms -- the value comes from the peer's documented ceiling, not from the symptom. A dead connection is still reaped: kRpPeerMaxRequestMs (10000) is unchanged and is the absolute ceiling. The cost is that a dead peer holds the single-client server for up to 6 s rather than 2 s before that applies. Measured on the attached pair, 10 reconnect cycles per run: before master 2 pass / 1 fail unrelated branch 1 pass / 1 fail after 6 runs 6 pass, 0 stalls Six clean runs against a ~40% failure rate is roughly a 1-in-20 coincidence, so this is strong but not proof for a fault of this shape; the six-millisecond miss is what carries it. Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51 Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
The defect
The RP HTTP client gave each request 2000 ms. The peer's HTTP server allows itself 5000 ms for the same request. The client was therefore abandoning work the server was still legitimately performing.
The peer does not answer from its network task. On ESP,
handle_esp_request()queues the request to the sketch's main loop and blocks on a semaphore waiting for it:Nothing is written until that completes, so response latency is bounded by the peer's loop cadence, not by transmission. That is why 4-to-55-byte static string responses are slow: measured median 552 ms, p90 890 ms, over 360 samples.
Evidence that the budget was the fault, not the peer
This was not guessed from the code. The client was instrumented first (#4229) and the fix follows the measurement.
At 2000 ms — 241 cycles, 4 hard failures. Every one had
elapsed_msof exactly 2000, the socket still open at both checkpoints, andbody_read = 0:Exactly 2000 ms is the client's own deadline; the peer neither closed nor reset. Failures appeared on three different endpoints (
/leds,/status,/ping), and the 4096-byte echo never failed once — so neither endpoint nor payload size was implicated.At the larger budget — 215 cycles, 0 failures, and the confirming observation. Five requests exceeded 2000 ms and completed correctly:
GET /ledsGET /ledsGET /rpc/discoverGET /ledsGET /rpc/discoverEach would have failed under 2000 ms. This is the positive evidence, not merely an absence of failures — I deliberately did not treat the zero-failure count as proof, because a zero is also consistent with the condition simply not occurring.
The maximum observed, 3586 ms, sits under the server's own 5000 ms budget, exactly as the mechanism predicts.
The change
One line: the deadline becomes
kRpPeerMaxRequestMs(10000 ms) instead of a hardcoded 2000 ms, so both sides of the fixture agree on how long a request may take rather than the client being stricter than the server.What this does not do
It does not make the peer faster. A bench fixture whose main loop can delay an HTTP response by 3.5 s is worth addressing on its own, and this change does not address it — it stops the client from misreporting that latency as a peer failure. Reducing the C6's loop cadence is a separate piece of work.
Verification
bash compile rp2350 --examples AutoResearchsucceeds.Diagnostics that produced this: #4229 (
elapsed_ms,peer_open_after_*) and #4230 (names the failing sub-test). Fixes the HTTP leg of #3899.🤖 Generated with Claude Code
https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
Summary by CodeRabbit