Cancel HTTP transport races when their timeout ends - #149
Conversation
📝 WalkthroughWalkthroughThe change replaces direct H3 racing with a shared concurrent request helper that manages cancellation, response-body cleanup, first-success selection, and aggregated errors. ChangesHTTP Request Racing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant httpRequest
participant raceHTTPRequests
participant RequestWorkers
participant ResponseBodies
httpRequest->>raceHTTPRequests: start labeled request functions
raceHTTPRequests->>RequestWorkers: run requests with racing context
RequestWorkers-->>raceHTTPRequests: responses or errors
raceHTTPRequests->>ResponseBodies: close failed and losing bodies
raceHTTPRequests-->>httpRequest: first 200 OK response or joined error
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
3815e50 to
1166546
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libcore/http_test.go (1)
137-184: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winTest doesn't exercise real connection/context-cancellation semantics.
winnerBody/lateBodyaretrackingReadClosermocks whoseClose()unconditionally returnsnil, regardless of the passed context's state. This test validates the scheduling contract ofraceHTTPRequests(winner returned, late body eventually closed) but can't detect the failure mode where a realnet/http/http3.Transportresponse body becomes unreadable once its request's context is canceled — which is exactly what happens indoH3Directtoday (see the critical comment onlibcore/http.go). Consider adding a test usinghttptest.NewServerand a realhttp.Clientbound to the race context to confirm the winning body stays readable afterraceHTTPRequests/doH3Directreturn.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libcore/http_test.go` around lines 137 - 184, Extend TestRaceHTTPRequestsFirstSuccessClosesLateBody with an httptest server and real http.Client requests bound to the race context, rather than relying only on trackingReadCloser mocks. Verify the winning response body remains readable after raceHTTPRequests returns and cancellation of the losing request, covering the real net/http context-cancellation behavior relevant to doH3Direct.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@libcore/http_test.go`:
- Around line 137-184: Extend TestRaceHTTPRequestsFirstSuccessClosesLateBody
with an httptest server and real http.Client requests bound to the race context,
rather than relying only on trackingReadCloser mocks. Verify the winning
response body remains readable after raceHTTPRequests returns and cancellation
of the losing request, covering the real net/http context-cancellation behavior
relevant to doH3Direct.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f0cf2744-b432-4f84-ab3a-3307b9ae276e
📒 Files selected for processing (2)
libcore/http.golibcore/http_test.go
1166546 to
7e0bba2
Compare
|
Added a real HTTP server regression test that delays the winning body, confirms the losing request is canceled, and reads the winner after parent-context cancellation. |
|
Exact head passed Namespace CI run 29213880616, including the production-tag libcore tests. |
Summary
Validation
Greptile Summary
This PR updates the direct HTTP transport race cleanup. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "fix(http): cancel direct request race on..." | Re-trigger Greptile