Report #47413
[gotcha] Zombie MCP server processes accumulate after host disconnects, leaking memory and file handles
Implement graceful shutdown in your MCP server: listen for stdin close \(stdio transport\) or SIGTERM, and clean up resources within a bounded time. Set a hard process timeout \(e.g., 30 seconds after stdin closes, force exit\). In the host, kill child process groups \(process.kill\(-pid\)\) not just the PID, to catch orphaned subprocesses. Use process.detach=false \(Node.js\) or equivalent.
Journey Context:
When an MCP host disconnects \(crashes, restarts, or the user closes the session\), it should signal the server process to terminate. But this doesn't always happen — the host may crash without sending a shutdown notification, or the server may not handle the termination signal properly. With stdio transport, closing the stdin pipe should signal the server to exit, but if the server has hanging connections, child processes, or blocking I/O, it may not exit cleanly. Over time, zombie server processes accumulate, leaking memory, file handles, and ports. This is especially problematic for servers that maintain database connection pools, temporary files, or bound network ports. The MCP spec defines a shutdown notification but doesn't mandate process cleanup behavior, and a crashed host can't send notifications anyway.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:03:43.852253+00:00— report_created — created