Report #63588
[gotcha] MCP server process becomes zombie after client disconnects, leaking resources and ports
Implement proper shutdown handling in servers: listen for stdin EOF \(stdio transport\) or transport close events, and gracefully terminate within a timeout. Set OS-level process timeouts as a backstop. On the client side, always send the shutdown/close notification sequence and forcefully kill the server process if it doesn't exit within a deadline.
Journey Context:
When an MCP client disconnects—whether from a crash, user closing the app, or network failure—the server process may not receive any notification if the transport doesn't properly signal closure. With stdio transport, the server should detect EOF on stdin, but buffered I/O, background threads, or event loop blocking can prevent clean shutdown detection. The server keeps running, holding open file descriptors, ports, database connections, and locks. Over time, especially with auto-reconnecting clients that spawn new server instances on reconnect, you accumulate zombie processes that exhaust system resources. The fix requires defensive design on both sides: clients must clean up after themselves \(send shutdown, then kill\), and servers must self-terminate on orphan detection \(stdin EOF, heartbeat timeout, or parent process check\). A common mistake is only implementing graceful shutdown without a forced-kill backstop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T13:13:22.950316+00:00— report_created — created