Repository navigation
Conversation
…xtprotocol#937) closeGracefully() sent TERM and then waited on Process#onExit with no limit, so a server that ignores TERM kept the transport from closing and left the process running. - ServerParameters gets processTerminationTimeout (default 10 s, must be positive and fit in Long.MAX_VALUE nanoseconds) - After TERM, closeGracefully() waits up to that timeout, then calls destroyForcibly() and waits for the exit - StdioClientTransportTerminationTests covers a server that ignores TERM, one that exits on TERM, and the builder validation
This branch has not been deployed
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.
Closes #937.
Problem.
StdioClientTransport.closeGracefully()sends TERM (Process#destroy) and then waits onProcess#onExit()with no limit. A server that ignores TERM keepscloseGracefully()from ever completing, and the process stays alive. Reproduced onmainwithsh -c "trap '' TERM; while :; do sleep 1; done": no completion within 15 s, child still running (details in the issue).Change. This follows the surface proposed in the issue:
ServerParameters.Builder#processTerminationTimeout(Duration)andServerParameters#getProcessTerminationTimeout(). Default 10 s. The value must be positive and fit inLong.MAX_VALUEnanoseconds; a largerDurationwould overflow when Reactor schedules the timeout.closeGracefully(), afterdestroy(), the wait ononExit()is bounded by that timeout. On timeout it logs a warning, callsdestroyForcibly()and waits for the exit. The scheduler disposal that follows is unchanged.docs/client.md: one paragraph on the timeout in the STDIO section.Existing constructors and methods are unchanged; the additions are source and binary compatible. One behavior change: a server that needs more than 10 s to exit after TERM is now killed. Callers that need longer can raise the timeout.
Relation to #966. #966 replaces
process.destroy()withdestroyProcessTree(process)on the same line. The two changes compose: tree destroy for the TERM step, then this bounded wait and forced fallback. Whichever merges second needs a trivial rebase on that line.Tests.
StdioClientTransportTerminationTests(inmcp-test, next toStdioClientTransportTests):closeGracefully()completes within 10 s and the process is gone (POSIX only; on Windowsdestroy()isTerminateProcessand cannot be ignored);Without the change, the first scenario does not complete within 15 s (the reproduction posted on the issue).
Validation (Linux, JDK 25):
./mvnw install -pl mcp-core: 505 tests, 0 failures, javaformat validate ok../mvnw test -pl mcp-test -Dtest='Stdio*': all pass. The surefire "kill self fork JVM ... 30 seconds after System.exit(0)" message also appears onmainwithout this change.