fix: detect ungraceful stdin close and self-terminate#2325
Open
D2758695161 wants to merge 1 commit intogithub:mainfrom
Open
fix: detect ungraceful stdin close and self-terminate#2325D2758695161 wants to merge 1 commit intogithub:mainfrom
D2758695161 wants to merge 1 commit intogithub:mainfrom
Conversation
Add a stdin watchdog goroutine that monitors os.Stdin for EOF (broken pipe). When the MCP client crashes or is force-killed, stdin closes and the watchdog triggers shutdown, allowing the container to exit cleanly. Without this, orphaned containers accumulate since --rm only fires on graceful exit. After several orphans accumulate, concurrent MCP tool calls start hanging indefinitely. Fixes github#2323
eagle19900203-boop
approved these changes
Apr 14, 2026
Author
|
Thank you for the approval! Is there anything else needed before merge? Happy to address any feedback. |
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.
Fix: Detect ungraceful stdin close and self-terminate
Fixes #2323 — Docker containers leak when MCP client disconnects ungracefully
Problem
When the MCP client (Cursor, VS Code, Claude Code) is force-killed or crashes, the
docker run -i --rmcontainer does not exit because:--rmonly fires on graceful exitSolution
Added a stdin watchdog goroutine in
RunStdioServerthat monitorsos.Stdinfor EOF. When the MCP client disconnects ungracefully, stdin returns EOF and the watchdog triggers graceful shutdown, allowing the container to exit cleanly.Why this approach
stop()triggers graceful shutdown viasignal.NotifyContext--rmthen removes the container before the next sessionAlternative approaches considered
--name) — doesn't clean up existing orphansdocker pscleanup cron — requires user interventionTesting