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

Function onDaemonLost

src/mcp/proxy.ts:580–595  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

578 // hang. Instead, fall back to the in-process engine until a daemon answers
579 // again, and re-serve whatever the dead daemon never answered.
580 const onDaemonLost = (): void => {
581 if (shuttingDown || daemonSocket !== socket) return; // host teardown, or already handled
582 daemonStatus = 'failed';
583 daemonSocket = null;
584 try { socket.destroy(); } catch { /* ignore */ }
585 process.stderr.write(
586 `[CodeGraph MCP] Shared daemon connection lost; serving this session in-process (degraded), re-serving ${inflight.size} in-flight request(s).\n`
587 );
588 const orphaned = [...inflight.values()];
589 inflight.clear();
590 for (const line of orphaned) void handleLocally(line);
591 // A link that stayed up past the longest wait starts the backoff over; one
592 // that keeps dropping right after it attaches keeps backing off.
593 if (Date.now() - attachedAt >= retryMaxMs) retryDelayMs = retryBaseMs;
594 scheduleDaemonRetry();
595 };
596 socket.on('close', onDaemonLost);
597 socket.on('error', onDaemonLost);
598 // A daemon that came up mid-session has never seen this client: prime its

Callers

nothing calls this directly

Calls 5

handleLocallyFunction · 0.85
scheduleDaemonRetryFunction · 0.85
writeMethod · 0.65
destroyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected