Skip to content

Fix busy-spin CPU pin after stdio transport disconnects - #29

Open
bessavagner wants to merge 1 commit into
assafelovic:masterfrom
bessavagner:fix/stdio-busy-spin-shutdown
Open

Fix busy-spin CPU pin after stdio transport disconnects#29
bessavagner wants to merge 1 commit into
assafelovic:masterfrom
bessavagner:fix/stdio-busy-spin-shutdown

Conversation

@bessavagner

Copy link
Copy Markdown

Summary

  • run_server() had a trailing while True: pass meant to "keep the process alive" after mcp.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).
  • The empty spin loop has no sleep/yield, so it pins one CPU core at 100% indefinitely until the process is manually killed.
  • Easy to reproduce: any MCP client that spawns this server over stdio and later disconnects leaves an orphaned process spinning at 100% CPU forever. I hit this myself — the process had been running at 100% CPU for over two days before I noticed.

Fix

Remove the busy-spin loop and let run_server() exit cleanly with a log line once mcp.run() returns, since there's nothing left to do at that point.

Test plan

  • Read through run_server() control flow to confirm mcp.run() is blocking and the trailing code only runs after shutdown
  • Ran the server locally over stdio and confirmed it now exits cleanly on disconnect instead of spinning

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.
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