fix(stdio): cancel supervisor job on close to prevent process hang after EOF#735
Open
blackwell-systems wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Conversation
…ayloadResult The content-based polymorphic deserializer matches GetTaskResult on the presence of "taskId" alone. This incorrectly captures GetTaskPayloadResult responses (tasks/result), which wrap arbitrary JSON and may also contain a "taskId" key but not a "status" key. Tighten the discriminator to require both "taskId" and "status", since GetTaskResult always has both fields. GetTaskPayloadResult responses (which lack "status") now correctly fall through to other deserializers or the empty result handler. Fixes modelcontextprotocol#601 Signed-off-by: Dayna Blackwell <dayna@blackwell-systems.com>
…ter EOF When stdin reaches EOF, StdioServerTransport.close() cleans up all child jobs and invokes the onClose callback. However, the supervisor job backing the coroutine scope was never cancelled, keeping the scope alive indefinitely. This caused the server process to hang after the client disconnected. Cancel the supervisor job at the end of close() so the coroutine scope completes and the process can exit. Fixes modelcontextprotocol#708 Signed-off-by: Dayna Blackwell <dayna@blackwell-systems.com>
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.
Motivation and Context
Fixes #708
When a client closes stdin (e.g., Docker container shutdown, opencode disconnect),
StdioServerTransport.close()cleans up all child jobs (reading, processing, sending), flushes and closes I/O streams, and invokes theonClosecallback chain. However, theSupervisorJobbacking the coroutine scope was never cancelled, keeping the scope alive indefinitely. The server process hangs even though all meaningful work has completed.Fix
Extract the
SupervisorJobinto a named field and cancel it at the end ofclose(), after all cleanup is done. This allows the coroutine scope to complete and the process to exit.How Has This Been Tested?
StdioServerTransportTestpasses (all tests green)supervisorJob.cancel()) at the end of the already-testedclose()methodexitProcess(0)) would no longer be necessaryTypes of changes
Checklist