MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / startPpidWatchdog

Function startPpidWatchdog

src/mcp/proxy.ts:703–725  ·  view source on GitHub ↗

* PPID watchdog mirroring the one in `MCPServer.start` — kills the proxy if * the MCP host (or its proxy of a host, see HOST_PPID_ENV) goes away without * closing stdin. Issue #277 documents why we can't rely on stdin EOF on * Linux: the parent may be SIGKILL'd and reparenting doesn't close pipes

(socket: net.Socket)

Source from the content-addressed store, hash-verified

701 * watchers to clean up, so this is cheap.
702 */
703function startPpidWatchdog(socket: net.Socket): void {
704 const pollMs = parsePollMs(process.env.CODEGRAPH_PPID_POLL_MS);
705 if (pollMs <= 0) return;
706 // Baseline from the CLI entry's earliest capture, not process.ppid here —
707 // a launcher killed during our first ~100ms would otherwise leave the
708 // baseline at 1 and blind the divergence check forever (#1185).
709 const originalPpid = EARLY_PPID;
710 const hostPpid = parseHostPpid(process.env[HOST_PPID_ENV]);
711 const timer = setInterval(() => {
712 const reason = supervisionLostReason({
713 originalPpid,
714 currentPpid: process.ppid,
715 hostPpid,
716 isAlive: isProcessAliveLocal,
717 });
718 if (reason) {
719 process.stderr.write(`[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n`);
720 try { socket.destroy(); } catch { /* ignore */ }
721 process.exit(0);
722 }
723 }, pollMs);
724 timer.unref?.();
725}
726
727function parsePollMs(raw: string | undefined): number {
728 return parseDelayMs(raw, DEFAULT_PPID_POLL_MS);

Callers 1

runProxyFunction · 0.85

Calls 6

supervisionLostReasonFunction · 0.90
parsePollMsFunction · 0.85
exitMethod · 0.80
parseHostPpidFunction · 0.70
writeMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected