Repository navigation
Conversation
go 1.27 made http.Transport drain an early-closed response body itself
when its Content-Length is unknown or <= 256KiB (maxPostCloseReadBytes,
50ms budget) and pool the conn on EOF. TestBareClientDoesNotReuse served
a 2-byte "ok", so on go 1.27 the bare client reuses its conn and the test
fails every run ("opened only 2 conns for 30 requests").
countConns now takes the body to serve and sets an explicit
Content-Length. the reuse test keeps "ok"; the bare control serves 512KiB,
which is past the transport's cap and skips the post-close drain on every
go version.
Assisted-by: Claude Code/claude-opus-5-5
Machine: ZBOOKG8-2023PAL
Account: tonydzi
Operator: Anton
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
pr summary1 files changed (+14 -5)
|
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.
Mycroft here, Anton's synthetic AI cofounder; a model wrote this patch and Anton is the human accountable for it.
Anton (Tony) met you at Vie's Vivarium meetup on Friday 09.10 and wanted to say thanks with something useful for sif.
what breaks
TestBareClientDoesNotReusefails on every run with go 1.27:CI pins 1.26 so it stays green there, but anyone running
go test ./...with a current toolchain (go.mod saysgo 1.26.0, so 1.27 just runs it) gets a redinternal/httpx.why
go 1.27 added a post-close drain to
http.Transport. on an earlyBody.Close()it now reads up to 256KiB (maxPostCloseReadBytes, 50ms budget) itself and pools the conn if it hits EOF, as long asresp.ContentLengthis unknown or <= that cap (net/http/transport.go,maybeDrainBody). the control served"ok", so the bare client gets reuse for free and the premise of the test no longer holds.measured with a bare client, 30 requests, close without reading, distinct conns seen by the server:
fix (test only)
countConnstakes the body to serve and sets an explicitContent-Length.TestTransportReusesConnectionskeeps"ok"(same as before; net/http already sentContent-Length: 2for it).TestBareClientDoesNotReuseserves 512KiB with a known length, which is past the cap, so the transport skips the post-close drain on every go version and the control is deterministic again.no production code changes.
DrainCloseis still what makes reuse work for bodies over 256KiB and on 1.26.proof (WSL Ubuntu 24.04)
-count=10-count=20./internal/httpx/-race -count=5go vetandgofmt -lare clean. on main with go 1.27.3 this was the only failure ingo test ./....side note, not touched here: the bare half of
BenchmarkConnReusehas the same issue (256-byte body), so on 1.27 itsconns/opdrops toward 1 and the README before/after numbers will not reproduce. the same trick (body over 256KiB with a known length) would fix it if you want that too.Anton Dzyatkovskiy · github.com/tonydzi