streamable client: Connect blocks far past its context deadline against an unresponsive server (detached-context cleanup)
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Comienza en mcp/streamable.go, alrededor de la implementación de StreamableClientTransport.Connect cerca de la línea 2045, y luego sigue la limpieza posterior a un fallo de inicialización. Ejecuta la reproducción proporcionada TestConnectOvershootsDeadline para observar el retraso. Se considera terminado cuando Connect retorna aproximadamente para la fecha límite del llamador incluso cuando el servidor acepta conexiones pero nunca responde, con cobertura de regresión para ese comportamiento.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 5.3k
- Forks
- 607
- Merge medio
- 1 d 16 h
- PR fusionados (30 d)
- 81
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/go-sdk
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoneeds investigation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelcontextprotocol/go-sdk#745 · 13 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 50/100
modelcontextprotocol/go-sdk#1492 ·
Los mantenedores suelen responder en 1 día
-
mcp: a second subscriptions/listen for the same URI silences the firstPosiblemente ocupada @jmrplens la tomó hace 1 día. Abierto
modelcontextprotocol/go-sdk#1489 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
mcp: ClientSession.CallTool omits Mcp-Param-* headers unless the tool is in the ListTools cache, so a call without a prior tools/list is rejectedPosiblemente ocupada @huynle-dev la tomó hace 1 día. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
modelcontextprotocol/go-sdk#1481 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)Posiblemente ocupada @huynle-dev la tomó hace 1 día. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 32/100
modelcontextprotocol/go-sdk#1480 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/go-sdk
Issues similares
-
CLI: `describe <ns>.<table>` reports "namespace does not exist" when only the table is missingPosiblemente ocupada @Shruthirdy la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
apache/iceberg-go#2423 ·
Los mantenedores suelen responder en 2 días
-
post-v4
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
rishikanthc/Scriberr#506 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
microsoft/TypeScript#65290 ·
Los mantenedores suelen responder en 1 día
-
[Bug] rollingUpdatePartition panics when live StatefulSet replicas sit far below the desired countAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
sgl-project/rbg#547 ·
Los mantenedores suelen responder en 1 día