modelcontextprotocol / modelcontextprotocol/java-sdk
StdioClientTransport should support bounded child process termination
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 3.7k
- Forks
- 1.1k
- Merge moyen
- 1 j 15 h
- PR mergées (30 j)
- 9
Description
StdioClientTransport starts and manages a child MCP server process. During graceful shutdown, the SDK transport currently calls process.destroy() and waits for process.onExit().
That works when the child process responds to SIGTERM, but it can hang indefinitely if the child process ignores termination or becomes stuck. Downstream, we had to implement a custom McpClientTransport to ensure proxied MCP server processes are always cleaned up when the parent shuts down.
Current behavior
The current shutdown flow is effectively:
if (this.process != null) {
this.process.destroy();
return Mono.fromFuture(process.onExit());
}
There is no configurable timeout and no fallback to destroyForcibly().
Expected behavior
StdioClientTransport.closeGracefully() should support bounded process termination:
- Stop accepting new messages.
- Complete the transport sinks.
- Send graceful termination with
process.destroy(). - Wait up to a configurable timeout.
- If the process is still alive, call
process.destroyForcibly(). - Dispose the transport schedulers.
This guarantees that child MCP server processes do not survive parent shutdown indefinitely.
Proposed fix
Add a configurable process termination timeout to StdioClientTransport, with a sensible default.
Conceptually:
process.destroy();
return Mono.fromFuture(process.onExit())
.timeout(processTerminationTimeout, Mono.defer(() -> {
if (process.isAlive()) {
process.destroyForcibly();
}
return Mono.fromFuture(process.onExit());
}));
This could be exposed through the existing ServerParameters builder or a dedicated StdioClientTransport constructor/builder option.
Suggested regression test
Add a test with a child process that ignores SIGTERM or does not exit promptly.
The test should verify that:
closeGracefully()completes within the configured timeout plus a small buffer.- The child process is no longer alive after
closeGracefully()completes. - The transport schedulers and sinks are cleaned up.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par StdioClientTransport.closeGracefully() et examinez comment ServerParameters configure le transport et comment process.onExit() est attendu. Ajoutez un délai d'expiration configurable pour la terminaison, puis exécutez ou ajoutez le test de régression suggéré avec un processus enfant qui ignore SIGTERM. Le travail est terminé lorsque l'arrêt s'achève dans la marge du délai d'expiration, qu'un processus enfant toujours actif est terminé de force et que les schedulers et les sinks sont nettoyés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 55/100