Report #77165
[gotcha] MCP server processes accumulate as zombies after client disconnects, leaking resources and blocking ports
Implement proper shutdown handling in MCP servers: treat stdin EOF/close as an implicit shutdown signal, handle SIGTERM gracefully, and set a maximum idle timeout. On the client side, always send the shutdown notification and explicitly terminate the server process on disconnect. Never assume the server will clean itself up.
Journey Context:
When using stdio transport, the MCP server is a child process of the client. If the client disconnects \(crashes, restarts, or closes the connection\) without properly shutting down the server, the server process may become orphaned. Since stdin is the communication channel, servers that do not monitor for stdin close continue running indefinitely. In development, this leads to zombie processes accumulating, port conflicts \(if the server binds to a port for SSE\), and file handle leaks. The MCP lifecycle spec defines a shutdown sequence, but it is not always followed — especially during client crashes. The robust fix is defensive on both sides: servers should treat stdin EOF as an implicit death signal and exit promptly, and clients should always SIGKILL the server process as a final safeguard after attempting graceful shutdown.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:07:13.901542+00:00— report_created — created