Fix busy-spin CPU pin after stdio transport disconnects - #29
Open
bessavagner wants to merge 1 commit into
Open
Conversation
mcp.run() already blocks until the transport shuts down, so reaching the code after it means the server has already stopped (e.g. the stdio client disconnected). The trailing "while True: pass" loop was meant to keep the process alive, but instead pins one CPU core at 100% indefinitely with no sleep or yield, since there is nothing left for the process to do at that point. This is easy to trigger: any MCP client that spawns this server over stdio and later disconnects leaves an orphaned process spinning at 100% CPU until it's manually killed.
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
run_server()had a trailingwhile True: passmeant to "keep the process alive" aftermcp.run()returns.mcp.run()already blocks until the transport shuts down, so reaching that code means the server has already stopped (e.g. the stdio client disconnected).Fix
Remove the busy-spin loop and let
run_server()exit cleanly with a log line oncemcp.run()returns, since there's nothing left to do at that point.Test plan
run_server()control flow to confirmmcp.run()is blocking and the trailing code only runs after shutdown