Skip to content

fix(net): stop abandoning requests the peer is still serving - #4231

Merged
zackees merged 3 commits into
masterfrom
fix/rp-http-client-deadline
Sep 9, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/rp-http-client-deadline

Conversation

@zackees

@zackees zackees commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

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:

httpd task → xQueueSend(s_esp_request_queue) → blocks 5000 ms on a semaphore
                      ↓
     ServerAsyncRunner::update()  ←  task::Executor, pumped from the MAIN task

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_ms of exactly 2000, the socket still open at both checkpoints, and body_read = 0:

GET /status  'Truncated response body'  body_read=0  elapsed_ms=2000
             status_line='HTTP/1.1 200'  content_length=54
             peer_open_after_status=True  peer_open_after_body=True

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:

Request Elapsed
GET /leds 2706 ms
GET /leds 2734 ms
GET /rpc/discover 2961 ms
GET /leds 3108 ms
GET /rpc/discover 3586 ms

Each 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 AutoResearch succeeds.
  • Behaviour measured across 456 cycles total on the RP2350W/ESP32-C6 bench.

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

  • Bug Fixes
    • Improved RP2350W CYW43 HTTP request handling by allowing the client to wait for the full server request window.
    • Prevented valid, longer-running requests from timing out prematurely.

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
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6f03f16f-5ce0-4cde-854a-87d1f14ba010

📥 Commits

Reviewing files that changed from the base of the PR and between 1dba013 and b1ef39e.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearchNet.cpp
  • wiki

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7b346d9a-135a-47ec-a452-99a7604165b6

📥 Commits

Reviewing files that changed from the base of the PR and between d5e9f0d and 1dba013.

📒 Files selected for processing (1)
  • examples/AutoResearch/AutoResearchNet.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

RP2350W HTTP request timing

Layer / File(s) Summary
Align response deadline with peer budget
examples/AutoResearch/AutoResearchNet.cpp
runRpHttpRequestTest records the request start time after sending the request body and sets the response deadline to request_started_ms + kRpPeerMaxRequestMs.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 1dba0

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: extending the request deadline so the client does not abandon requests while the peer is still serving them.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rp-http-client-deadline

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.

@zackees

zackees commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Went DIRTY after this pass merged #4220, #4221 and #4227, which rewrote the same region of ci/autoresearch/net.py.

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.

zackees and others added 2 commits September 9, 2026 10:48
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
@zackees
zackees merged commit ba54bf7 into master Sep 9, 2026
25 of 27 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 9, 2026
zackees added a commit that referenced this pull request Sep 12, 2026
…#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]>
@zackees
zackees deleted the fix/rp-http-client-deadline branch November 5, 2026 05:53
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