Repository navigation
Close the response body in the wait command's poll loop - #2700
Draft
rootkiller6788 wants to merge 2 commits into
Draft
rootkiller6788 wants to merge 2 commits into
rootkiller6788 wants to merge 2 commits into
Conversation
The wait subcommand hits the startup endpoint once a second until it gets a 200 and never closed the response body. Go can't hand the connection back to the pool unless the body is read and closed, so each poll burned a new connection to the proxy. Read the body into io.Discard and close it before checking the status code, so both the ready and the still-starting paths release it.
Adds a test that swaps in a RoundTripper which keeps a handle on the response bodies it returns, then runs wait against both a 200 and a 503 so both exit paths are covered. Fails without the fix.
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.
The
waitsubcommand polls the other proxy's/startupendpoint once a second until it gets a 200, and it never closed the response body. Go only returns a connection to the pool if the body is read and closed, so every poll opened a fresh connection to the proxy instead of reusing one. With the default 30s--maxthat's up to 30 connections, and the command is meant to be run in tight sidecar/init-container loops.The fix reads the body into
io.Discardand closes it before checking the status code, so both the ready and the still-starting paths release it. Behaviour is otherwise unchanged: same retry cadence, same timeout.The test installs a
RoundTripperonhttp.DefaultClientthat keeps a handle on the bodies it hands out, then runswaitagainst a 200 and a 503 so both exit paths are covered. It fails on current main withresponse body was left openand passes with the fix.