Report #56536
[gotcha] Killed MCP client leaves orphan server processes running indefinitely
Spawn MCP servers in their own process group. Register shutdown hooks \(atexit, signal handlers for SIGTERM/SIGINT\) that send SIGTERM to the entire process group. Implement a heartbeat/keepalive in the MCP server that exits if no request is received within a configurable timeout. On client restart, check for and kill stale server processes before spawning new ones.
Journey Context:
MCP servers are typically spawned as child processes by the client. If the client crashes or is force-killed \(SIGKILL\), it never sends the cleanup signal. The server process continues running, holding ports, file locks, and resources. On restart, the new client may fail to bind the same port or conflict with the orphan. This is a classic process-lifecycle gotcha that is easy to miss in development \(where you restart cleanly\) but bites in production \(where crashes are messy\). SIGKILL cannot be caught, so atexit handlers alone are insufficient — you need the heartbeat timeout on the server side as a backstop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:23:20.315015+00:00— report_created — created