Skip to content

fix(coderd/x/chatd/mcpclient): use dedicated HTTP transport per MCP connection - #23494

Merged
kylecarbs merged 2 commits into
mainfrom
fix/mcpclient-transport-flake
Mar 24, 2026
Merged

kylecarbs merged 2 commits into
mainfrom
fix/mcpclient-transport-flake

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

Problem

TestConnectAll_MultipleServers flakes with:

net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called

Each MCP client connection implicitly uses http.DefaultTransport. When httptest.Server.Close() runs during parallel test cleanup, it calls CloseIdleConnections on http.DefaultTransport, breaking in-flight connections from other goroutines or parallel tests sharing that transport.

Fix

Clone the default transport for each MCP connection via http.DefaultTransport.(*http.Transport).Clone(), passed through WithHTTPBasicClient (StreamableHTTP) and WithHTTPClient (SSE). This scopes idle connection cleanup to a single MCP server so it cannot disrupt unrelated connections.

Fixes coder/internal#1420

…onnection

Each MCP client connection was implicitly using http.DefaultTransport.
When httptest.Server.Close() runs during parallel tests, it calls
CloseIdleConnections on http.DefaultTransport, breaking in-flight
connections from other tests or goroutines within the same test.

Clone the default transport for each connection so that idle connection
cleanup is scoped to a single MCP server and cannot disrupt unrelated
connections.

Fixes coder/internal#1420

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this should be a util function

@kylecarbs
kylecarbs merged commit 13241a5 into main Mar 24, 2026
26 checks passed
@kylecarbs
kylecarbs deleted the fix/mcpclient-transport-flake branch March 24, 2026 13:22
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: TestConnectAll_MultipleServers

2 participants