streamable client: Connect blocks far past its context deadline against an unresponsive server (detached-context cleanup)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
mcp/streamable.go の 2045 行付近にある StreamableClientTransport.Connect の実装から始め、初期化に失敗した後のクリーンアップを追ってください。遅延を確認するため、提供されている再現テスト TestConnectOvershootsDeadline を実行してください。サーバーが接続を受け入れるものの応答しない場合でも、Connect が呼び出し元の deadline までのおおよその時点で戻り、この動作に対するリグレッションカバレッジがあることが完了条件です。
索引モデルが issue の本文から書いたものです。
説明
What
Client.Connect with a context deadline can block far past that deadline against a server that accepts TCP connections but never responds (black-holed peer). Observed: a 2s deadline returns after ~12s with the default HTTP client in a local test; in production, with connections crossing a NAT that silently dropped packets, a 10s deadline stretched to ~125s (kernel TCP timeout).
The caller's deadline bounds the initialize request itself, but not the error-path cleanup that follows. StreamableClientTransport.Connect detaches the incoming context for the connection's lifecycle (connCtx, cancel := context.WithCancel(xcontext.Detach(ctx)), mcp/streamable.go ~L2045 in v1.7.0). That detachment is intentional and documented for keeping the standalone SSE stream alive past a short connect deadline. However, when initialize fails at the deadline, the cleanup work that runs before Connect returns (the notifications/cancelled write for the abandoned call and session.Close()) issues HTTP requests bound to the detached connection context, not to the caller's expired one. Against a black-holed server those requests block until the HTTP transport or the kernel gives up, so Connect overshoots its deadline by minutes with a default http.Client (no ResponseHeaderTimeout).
Related: #1183 covers the same detached-context ordering problem for Close() specifically. This report is about Connect not honoring its own deadline on the error path.
Repro
func TestConnectOvershootsDeadline(t *testing.T) {
// Accepts TCP connections, never responds to any request.
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
go func() {
for {
conn, err := ln.Accept()
if err != nil {
return
}
defer conn.Close()
}
}()
client := mcp.NewClient(&mcp.Implementation{Name: "c", Version: "0"}, nil)
tr := &mcp.StreamableClientTransport{Endpoint: "http://" + ln.Addr().String()}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
start := time.Now()
_, err = client.Connect(ctx, tr, nil)
elapsed := time.Since(start)
t.Logf("Connect returned after %s, err=%v", elapsed, err)
if elapsed > 4*time.Second {
t.Fatalf("Connect blocked %s past a 2s deadline", elapsed)
}
}
With go-sdk v1.7.0 and Go 1.24 this fails: Connect returned after 12.03s, err=context deadline exceeded; sending "notifications/cancelled": rejected by transport: Post "http://127.0.0.1:...": context deadline exceeded.
Expected
Connect(ctx, ...) returns within (approximately) ctx's deadline regardless of server behavior. Error-path cleanup for a session that never initialized could be best-effort/asynchronous, or bounded by the caller's context rather than the detached connection context.
Workaround
We now run Connect+ListTools in a goroutine and select on the deadline, abandoning the goroutine on timeout, plus a cloned http.Transport with ResponseHeaderTimeout and a short dial timeout (https://github.com/coder/coder/pull/28400).
🤖 Filed by Mux (AI agent) on behalf of @ibetitsmike.
- 主要言語
- Go
- スター
- 5.3k
- フォーク
- 607
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 80
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/go-sdk のほかの issue
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンneeds investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/go-sdk#745 · コメント 13 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
mcp: a second subscriptions/listen for the same URI silences the first対応中かも @jmrplens が今日担当しました。 オープン
modelcontextprotocol/go-sdk#1489 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
mcp: ClientSession.CallTool omits Mcp-Param-* headers unless the tool is in the ListTools cache, so a call without a prior tools/list is rejected対応中かも @huynle-dev が今日担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
modelcontextprotocol/go-sdk#1481 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)対応中かも @huynle-dev が今日担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 32/100
modelcontextprotocol/go-sdk#1480 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
mcp: Client.Connect falls back to initialize after a 401 on server/discover, running the authorization flow twice対応中かも @kerthans が 13 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
modelcontextprotocol/go-sdk#1423 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/go-sdk の issue をすべて見る
似ている issue
-
Fix mode unpins a reusable workflow call when the same repository is also used as a step actionオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
github/gh-actions-lock#261 ·
メンテナーはふだん 1 日以内に返信
-
bug documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
labmonkeys-space/nl6#974 ·
メンテナーはふだん 1 日以内に返信
-
model:sonnet phase-2-optimize runtime:claude security size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
FootprintAI/Containarium#3471 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] serviceenvupdater filter does not update KUBERNETES_SERVICE_HOST/PORT in init containers対応中かも @RaphaelFakhri が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openyurtio/openyurt#2845 ·
メンテナーはふだん 7 日以内に返信
-
fuzz.yml skips three fuzz targets, and the Action's user input describes only ~/.claude対応中かも @predictor2718 が今日担当しました。 オープンgithub_actions P3 tests
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信