fix(mcp): give allow-private-ips OAuth clients a private connection pool#3707
Merged
dgageot merged 1 commit intoJul 17, 2026
Merged
Conversation
oauthHTTPClientForAllowPrivateIPs(true) returned a client with a nil
Transport, i.e. http.DefaultTransport. Anything pruning that shared pool
via CloseIdleConnections — notably httptest.Server.Close, run by every
finishing parallel test — could break another client's in-flight request
("transport connection broken: http: CloseIdleConnections called"),
the same flake f7b5c10 fixed for the transports' base RoundTripper.
Clone the default transport instead: same proxy/HTTP2/timeout behavior,
private pool. TestMain's swapped-in client and the remaining nil-Transport
test clients now get private pools too.
Assisted-By: Claude
Sayt-0
approved these changes
Jul 17, 2026
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The fix correctly solves the connection-pool isolation problem. Giving each oauthHTTPClientForAllowPrivateIPs(true) call its own cloned transport prevents httptest.Server.Close (or any third-party CloseIdleConnections) from breaking in-flight requests made by other test clients.
Dismissed security findings (review manually)
pkg/tools/mcp/oauth_helpers.go:46— Unchecked type assertionhttp.DefaultTransport.(*http.Transport)(verifier mitigation: Go's stdlib always initializesDefaultTransportas*http.Transport; no code in this repo replaces it. The same pattern is used by the co-authored test helpernewTestTransport. Risk is purely theoretical.)
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.
Follow-up to f7b5c10 (#3704), which fixed a flaky-test root cause —
oauthTransportsharinghttp.DefaultTransportas its baseRoundTripper— but left two paths untouched. Both surfaced in CI on #3696 asnet/http: HTTP/1.x transport connection broken: http: CloseIdleConnections calledinTestUnmanagedOAuthFlow_LegacyMode_NoAuthorizeURLInElicitation. The culprit ishttptest.Server.Close, called by every finishing parallel test, which drains the sharedhttp.DefaultTransportidle-connection pool. When another test's OAuth client holds a connection from that same pool — between the server's 401 and the authorized retry — the connection is killed mid-flight.oauthHTTPClientForAllowPrivateIPs(true)returned a client with a nilTransport, so it fell back tohttp.DefaultTransport. The fix clones the default transport instead, giving each remote-client its own private pool while preserving the same proxy, HTTP/2, and timeout settings. The clone is constructed once per remote-client, so connection reuse within a single client is still effective. On the test side,newTestTransportsimilarly clones the default transport rather than returning a bare&http.Transport{},TestMainreuses the production helper so its swapped-in client is also isolated, and the callback-server test client gets a per-test transport.No behavior change in production beyond connection-pool isolation; the fix only affects which pool a client draws from.