Add timeout and fallback logging for closeGracefully() to prevent hanging shutdown
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 50/100
Línea de trabajo
Lee primero McpAsyncClient.closeGracefully() y, después, inspecciona initializer.closeGracefully() y transport.closeGracefully() para entender su comportamiento de finalización. Verifica que la gestión de timeouts, la advertencia y el cierre forzado como fallback, la gestión de errores y la finalización definitiva hagan que el apagado tenga un límite de tiempo sin cambiar el flujo graceful previsto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
When using McpAsyncClient.closeGracefully(), the client executes:
return this.initializer.closeGracefully()
.then(transport.closeGracefully());
Both initializer.closeGracefully() and transport.closeGracefully() return Mono<Void>.
However, if either of them hangs—for example:
- The underlying transport (HTTP/SSE/WebSocket) never completes
- The server doesn’t respond to shutdown
- A Reactor pipeline remains open (no
onComplete)
then the returned Mono never completes, causing the application to hang indefinitely during shutdown.
This results in JVMs or containers that never terminate, blocking CI/CD or production deployments.
Goal
Add a timeout and fallback mechanism to ensure that the client always terminates safely, even when the transport or initializer fails to complete.
Proposed Change
1. Wrap shutdown calls with timeout and fallback
Use Reactor’s timeout(Duration, fallbackMono) operator to guarantee a bounded shutdown duration.
public Mono<Void> closeGracefully() {
return Mono.defer(() -> {
long start = logger.isDebugEnabled() ? System.nanoTime() : 0L;
Duration timeout = Duration.ofSeconds(
Integer.getInteger("mcp.shutdown.timeout.seconds", 10));
Mono<Void> graceful = this.initializer.closeGracefully()
.then(transport.closeGracefully());
Mono<Void> fallback = Mono.fromRunnable(() -> {
logger.warn("closeGracefully() timed out after {} seconds; proceeding with best-effort shutdown.", timeout.getSeconds());
try {
this.transport.close(); // force-close if needed
} catch (Throwable t) {
logger.warn("Fallback forced close encountered error: {}", t.toString());
}
})
.then();
return graceful
.timeout(timeout, fallback)
.doOnError(e -> logger.warn("closeGracefully() failed: {}", e.toString()))
.onErrorResume(e -> Mono.empty()) // ensure app doesn't hang
.doFinally(sig -> {
if (logger.isDebugEnabled()) {
long durationMs = (System.nanoTime() - start) / 1_000_000;
logger.debug("closeGracefully() finished with signal={}, took {} ms", sig, durationMs);
}
});
});
}
Summary
Introduce a timeout and fallback mechanism for closeGracefully() to guarantee reliable termination, preventing hanging shutdowns when the transport or lifecycle initializer fails to complete.
- Lenguaje dominante
- Java
- Estrellas
- 3.7k
- Forks
- 1.1k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 9
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/java-sdk
-
area/transport bug P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
modelcontextprotocol/java-sdk#1124 · 1 comentario ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities Abiertobug P2 ready for work
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
modelcontextprotocol/java-sdk#1086 · 1 comentario ·
-
enhancement good first issue P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
modelcontextprotocol/java-sdk#898 · 1 comentario ·
Todos los issues de modelcontextprotocol/java-sdk
Issues similares
-
bug untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
opensearch-project/ml-commons#5094 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
emitter:client:csharp feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Abiertobug frontend maui-pilot
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100