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

Function startPpidWatchdog

src/mcp/proxy.ts:814–836  ·  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

812 * watchers to clean up, so this is cheap.
813 */
814function startPpidWatchdog(socket: net.Socket): void {
815 const pollMs = parsePollMs(process.env.CODEGRAPH_PPID_POLL_MS);
816 if (pollMs <= 0) return;
817 // Baseline from the CLI entry's earliest capture, not process.ppid here —
818 // a launcher killed during our first ~100ms would otherwise leave the
819 // baseline at 1 and blind the divergence check forever (#1185).
820 const originalPpid = EARLY_PPID;
821 const hostPpid = parseHostPpid(process.env[HOST_PPID_ENV]);
822 const timer = setInterval(() => {
823 const reason = supervisionLostReason({
824 originalPpid,
825 currentPpid: process.ppid,
826 hostPpid,
827 isAlive: isProcessAliveLocal,
828 });
829 if (reason) {
830 process.stderr.write(`[CodeGraph MCP] Parent process exited (${reason}); shutting down.\n`);
831 try { socket.destroy(); } catch { /* ignore */ }
832 process.exit(0);
833 }
834 }, pollMs);
835 timer.unref?.();
836}
837
838function parsePollMs(raw: string | undefined): number {
839 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