Skip to content

test(mcp): fix flaky OAuth tests by not sharing http.DefaultTransport#3704

Merged
Sayt-0 merged 1 commit into
docker:mainfrom
dgageot:test/fix-flaky-oauth-tests
Jul 17, 2026
Merged

test(mcp): fix flaky OAuth tests by not sharing http.DefaultTransport#3704
Sayt-0 merged 1 commit into
docker:mainfrom
dgageot:test/fix-flaky-oauth-tests

Conversation

@dgageot

@dgageot dgageot commented Jul 17, 2026

Copy link
Copy Markdown
Member

CI on main was intermittently failing with TestOAuthTransport_NonInteractiveCtxSkipsElicitation reporting "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 in pkg/tools/mcp/oauth_test.go shared http.DefaultTransport as the base transport for their OAuth wrappers. The Go stdlib's httptest.Server.Close calls http.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.Transport per test and registers a t.Cleanup to close its idle connections. All 15 base: http.DefaultTransport sites and the one http.DefaultClient.Do call 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=16 across the full pkg/tools/mcp package with no failures.

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)
@dgageot
dgageot requested a review from a team as a code owner July 17, 2026 07:54
@Sayt-0
Sayt-0 enabled auto-merge July 17, 2026 07:56

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Sayt-0
Sayt-0 merged commit 0b0b5ea into docker:main Jul 17, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants