streamable client: Connect blocks far past its context deadline against an unresponsive server (detached-context cleanup)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu trong mcp/streamable.go, xung quanh phần triển khai StreamableClientTransport.Connect gần dòng 2045, sau đó theo dõi quá trình dọn dẹp sau khi khởi tạo thất bại. Chạy bản tái hiện được cung cấp TestConnectOvershootsDeadline để quan sát độ trễ. Được xem là hoàn tất khi Connect trả về xấp xỉ vào deadline của caller, ngay cả khi server chấp nhận các kết nối nhưng không bao giờ phản hồi, cùng với kiểm thử hồi quy cho hành vi đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 5.3k
- Fork
- 607
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 80
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/go-sdk
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởneeds investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/go-sdk#745 · 13 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: a second subscriptions/listen for the same URI silences the firstCó thể đã có người làm @jmrplens đã nhận hôm nay. Đang mở
modelcontextprotocol/go-sdk#1489 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: ClientSession.CallTool omits Mcp-Param-* headers unless the tool is in the ListTools cache, so a call without a prior tools/list is rejectedCó thể đã có người làm @huynle-dev đã nhận hôm nay. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/go-sdk#1481 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)Có thể đã có người làm @huynle-dev đã nhận hôm nay. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 32/100
modelcontextprotocol/go-sdk#1480 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: Client.Connect falls back to initialize after a 401 on server/discover, running the authorization flow twiceCó thể đã có người làm @kerthans đã nhận 13 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
modelcontextprotocol/go-sdk#1423 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/go-sdk
Issue tương tự
-
needs-area
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Azure/typespec-azure#5936 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
-
Fix mode unpins a reusable workflow call when the same repository is also used as a step actionĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
github/gh-actions-lock#261 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
labmonkeys-space/nl6#974 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100