Skip to content

Fix stdio MCP server hang on Ctrl-C#27

Open
seanknox wants to merge 1 commit intoincident-io:mainfrom
seanknox:fix/stdio-shutdown-cancel
Open

Fix stdio MCP server hang on Ctrl-C#27
seanknox wants to merge 1 commit intoincident-io:mainfrom
seanknox:fix/stdio-shutdown-cancel

Conversation

@seanknox
Copy link

This PR fixes a shutdown bug in the stdio transport where Ctrl-C could log graceful shutdown but leave the MCP server running indefinitely. The process now exits promptly when cancellation is requested.

The issue was that shutdown depended on a blocking stdin decode loop. If stdin was idle, the server could not observe context cancellation, so it never completed shutdown after receiving SIGINT/SIGTERM.

This change decouples decoding from the shutdown path so cancellation is always observable, even when reads are blocked. It also treats context.Canceled as a normal stop in main, and adds regression tests that reproduce blocked-reader scenarios and assert clean termination.

Tested with go test ./....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant