fix: kill process tree on StdioClientTransport.close()#2024
Open
JoannaaKL wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: kill process tree on StdioClientTransport.close()#2024JoannaaKL wants to merge 1 commit intomodelcontextprotocol:mainfrom
JoannaaKL wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
close() only signaled the direct child PID, leaving descendants (e.g. from npx/uvx wrappers) running as orphans. - Spawn with detached: true on Unix so the child leads its own process group - Use process.kill(-pid) to kill the entire group on Unix - Use taskkill /T /F on Windows for tree kill - Fall back to direct ChildProcess.kill() if group kill fails Closes modelcontextprotocol#2023
e2897ec to
8d89c33
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StdioClientTransport.close()now kills the entire process tree, not just the direct child PIDdetached: trueon Unix so the child leads its own process groupprocess.kill(-pid)(process group kill) on Unix,taskkill /T /Fon WindowsChildProcess.kill()if the group kill fails (e.g. process already exited)Approach
This matches the dominant pattern in the Node.js ecosystem (used by execa, n8n, Mastra):
detached: true+process.kill(-pid, signal)— atomic, single syscall, no race conditionstaskkill /T /F /PID— the only viable tree-kill mechanism on Windows;detachedis skipped to avoid opening a console windowTest coverage
Added 7 new tests:
onclosecallback fires correctly with tree killclose()on already-exited process doesn't throwclose()called twice doesn't throwclose()called withoutstart()doesn't throw