test(mcp): fix flaky OAuth tests by not sharing http.DefaultTransport#3704
Merged
Conversation
httptest.Server.Close calls http.DefaultTransport.CloseIdleConnections, which broke in-flight requests of parallel tests sharing the default transport (seen in CI as "transport connection broken: http: CloseIdleConnections called" in TestOAuthTransport_NonInteractiveCtxSkipsElicitation). Each test now uses a private transport via a newTestTransport helper. Assisted-By: Claude (Anthropic)
Sayt-0
approved these changes
Jul 17, 2026
Sayt-0
enabled auto-merge
July 17, 2026 07:56
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The fix is sound. newTestTransport correctly allocates a fresh *http.Transport{} per test, and t.Cleanup(tr.CloseIdleConnections) ensures draining happens even on test failure. All 15 http.DefaultTransport substitutions and the one http.DefaultClient.Do replacement are correctly wired. No bugs, races, or resource leaks were introduced by the changed lines.
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.
CI on main was intermittently failing with
TestOAuthTransport_NonInteractiveCtxSkipsElicitationreporting "net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called". The failure appeared on a commit that only touched workflow YAML, which made it hard to track down. The root cause was that all ~15 parallel tests inpkg/tools/mcp/oauth_test.gosharedhttp.DefaultTransportas the base transport for their OAuth wrappers. The Go stdlib'shttptest.Server.Closecallshttp.DefaultTransport.CloseIdleConnections, so whenever any test tore down its server it could kill an in-flight connection belonging to another test running concurrently.The fix adds a
newTestTransport(t *testing.T)helper that allocates a fresh*http.Transportper test and registers at.Cleanupto close its idle connections. All 15base: http.DefaultTransportsites and the onehttp.DefaultClient.Docall in the test file are replaced with per-test transports. No production code is touched.The OAuth tests were stress-tested with
-race -count=20 -parallel=16across the fullpkg/tools/mcppackage with no failures.