Repository navigation
test(proxy): give the late-first-byte test a resend deadline that holds under load - #1020
Merged
Merged
Conversation
…ds under load The test used one 5 ms limit for both attempts. The first attempt does not depend on the limit, because its trace hook holds the byte until the watchdog cancels it. The resend does depend on it. Under -race on a loaded box the resend went silent past 5 ms and the call failed with "on two connections". Use 15 ms and 100 calls. Test-only, no behavior change. Closes #847 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
force-pushed
the
fix/flake-847
branch
from
November 10, 2026 08:47
df6fc9d to
497593f
Compare
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 497593f0f3c0 |
approve |
Verdict: approve
Findings
None.
Non-blocking
proxy/upstreamsilence_test.go:712— 100 calls lower the chance to catch a regression. The bad shape shows in about 1 call of 20, so one run of 100 calls catches it with about 99.4% chance (300 calls gave ~100%). A regressed build could pass about 1 run of 170. The mutation run in the PR (20 of 20 failures with the guard disabled) covers this today. Acceptable trade for a cost-neutral run.proxy/upstreamsilence_test.go:711— 15 ms is an empirical bound, not a guarantee. A box slower than the test box (4 busy-loop cores,-race, 0 failures in 200 runs) could still exceed it and bring the flake back. The test cannot do better without a production change:doWithSilenceGuarduses one silence value for both attempts.
What I checked
- The full diff: one commit, one test file, no production code. No behavior change, so the behavior-change and data-dependence rules do not apply.
- The comment's first claim: the limit bounds the resend too. True —
doWithSilenceGuardpasses the samesilenceto everysilenceAttempt(proxy/upstreamsilence.go:144), and a resend whose first byte is late is cancelled by its own watchdog. - The comment's second claim: the first attempt does not depend on the limit. True — the test hook
GotFirstResponseByte: func() { <-ctx.Done() }(proxy/upstreamsilence_test.go:719) holds the byte until the watchdog has cancelled.httptrace.WithClientTraceruns the newly added trace's hooks first, so the blocking hook runs before the guard's ownGotFirstResponseBytehook setsanswered; the watchdog therefore always fires, at any limit. No deadlock path: the watchdog seesanswered == falsewhile the hook blocks. - The math in the comment: 100 calls at 1-in-20 gives about 5 expected hits per run. Consistent with the PR's mutation result (20 of 20 failures).
- Test cost: 100 calls at ~15 ms is about the same run time as 300 calls at ~5 ms, as the PR states.
- Commit hygiene: DCO
Signed-off-bypresent,Assisted-By:attribution (notCo-Authored-By), conventional-commit title. - The PR's test evidence (0 failures in 200 runs after, 20 of 20 mutation failures) is the author's run on the eval box. I did not re-run it: live tests are not approved for this review.
amiddavid
commented
Nov 10, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 497593f0f3c0 |
approve |
Verdict: approve
One commit. It changes one test only: TestALateFirstByteOnTheRealTransportNeverReachesTheClient
in proxy/upstreamsilence_test.go. The silence limit goes from 5 ms to 15 ms, the loop from 300 to
100 calls, and a comment explains why. No production code changes, so no behavior change and no
data-dependence change.
Findings
None.
Non-blocking
proxy/upstreamsilence_test.go:709— "100 calls still find the 1-in-20 shape" is not a promise.
The shape appears on about 1 call in 20 (the file's own comment at line 695). The chance that 100
calls see none is0.95^100 = 0.59%. With the old 300 calls it was0.95^300 ≈ 0.00002%. So
about 1 run in 170 now passes without ever exercising the race it guards. Small, and it buys back
the 3-in-200 hard flake, so I accept it. If you want the coverage back, keep 300 calls and accept
a ~4.5 s test, or count the shape and assert a minimum.proxy/upstreamsilence_test.go:711— 15 ms lowers the flake but keeps its cause. One limit still
does two jobs: it arms the watchdog on the first attempt (where its length is irrelevant, the hook
holds the byte until the cancel) and bounds the resend's first byte. A load spike past 15 ms
re-creates the failure. A structural fix needs no timing margin: a resend that goes silent too
fails the call with the two-silences error, and the client still got no dead body — that outcome
is compliant, so the test could tolerate it and stay fatal only on the dead-body symptom
(a wrong body or a failed read). Then the limit could go back to 5 ms with 300 calls.
What I checked
- The full diff,
e37d14ca..HEAD: one file, 11 insertions, 2 deletions. Every changed line read. proxy/upstreamsilence.goin full: the watchdog arms onWroteRequestwith the samesilence
for every attempt (doWithSilenceGuardline 144), so the comment's premise — the limit also
bounds the resend — matches the code.- The claim that the first attempt does not depend on the limit. It holds. The blocking
GotFirstResponseBytehook on the first attempt waits forctx.Done(), which only the watchdog
closes. The watchdog cancels it whatever the limit is, becauseansweredis not stored before
the hook returns:httptrace.WithClientTraceruns the newer trace's hook first, and the older
hook (which storesanswered) runs only after the block ends. So the first attempt always ends
cancelled and resent, and its duration grows with the limit — the reason 100 calls, not 300, keep
the old ~1.5 s runtime. - The new failure mode the comment describes. At 5 ms, a resend whose answer took more than 5 ms
was itself cancelled, producederrUpstreamSilent"on two connections", and hit the
t.Fatalfat line 726. That matches the code path: one silence error is resent, a second is
returned (lines 126-131). - That nothing else references the old 5 ms / 300 values, and that the
silenceconst shadows
nothing in the function. - Live tests were not approved, so I did not run the test. The 3-in-200 figure is the author's
data; I could not reproduce it, only check that the code admits it.
This was referenced Nov 10, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test-only, no behavior change. Only
proxy/upstreamsilence_test.gochanges.Summary
What we found
-raceon a loaded box the answer can take more than 5 ms.What changed
How it was tested
Box, 4 busy-loop cores,
-race:go test -race -count=200 -run '^TestALateFirstByteOnTheRealTransportNeverReachesTheClient$' ./proxy/gave 3 failures in 200 runs.-racetest binary with-test.count=200: 0 failures in 200 runs.if false && err == nil && errors.Is(context.Cause(ctx), errUpstreamSilent)). The test fails 20 of 20 runs ("the client got a response whose watchdog had fired").go test -race ./proxy/...: ok.go vet ./proxy/andgofmt: clean.Closes #847