From 09439bbae0e41a055c92115651bf5b7bc4fdb6ce Mon Sep 17 00:00:00 2001 From: rrader26 Date: Mon, 11 May 2026 20:06:02 -0400 Subject: [PATCH] fix(mcp): exit on stdin close to prevent zombie servers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stdio MCP server only handled SIGINT/SIGTERM, so when a client died without sending a signal (Windows terminal close, Claude Code session exit, lost SSH pipe), the process kept running. Three zombies accumulated on a Win 11 ARM64 VM tonight, and Claude Code talked to one of the stale ones — so it served the pre-rebuild tool list and the AI couldn't see newly added tools. Hook into stdin 'end' and 'close' as a third exit path. Same cleanup sequence as the signal handlers (disposeAll + server.close + exit 0). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/mcp/server.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 3cc045f..4205777 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -93,6 +93,11 @@ export async function startMcpServer( } process.once('SIGINT', onShutdown) process.once('SIGTERM', onShutdown) + // If the client dies without sending a signal (Windows terminal close, + // Claude Code session exit, lost ssh pipe), stdin closes but the + // process otherwise has nothing to exit on. Don't let zombies pile up. + process.stdin.once('end', onShutdown) + process.stdin.once('close', onShutdown) return { stop } }