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

Method startLivenessTimers

src/mcp/daemon.ts:433–446  ·  view source on GitHub ↗

* Defense-in-depth against a daemon that outlives its clients (#692), for the * cases the refcount + idle timer miss because a socket close never arrives: * - **Inactivity backstop:** after `maxIdleMs` with no inbound traffic, reap * the daemon — but ONLY if no connected client can be

()

Source from the content-addressed store, hash-verified

431 * neither should hold it open on its own.
432 */
433 private startLivenessTimers(): void {
434 if (this.maxIdleMs > 0) {
435 const tick = Math.min(this.maxIdleMs, 60_000);
436 this.maxIdleTimer = setInterval(() => {
437 if (this.backstopShouldExit(isProcessAlive)) void this.stop('inactivity backstop');
438 }, tick);
439 this.maxIdleTimer.unref?.();
440 }
441 const sweepMs = resolveClientSweepMs();
442 if (sweepMs > 0) {
443 this.clientSweepTimer = setInterval(() => this.reapDeadClients(isProcessAlive), sweepMs);
444 this.clientSweepTimer.unref?.();
445 }
446 }
447
448 /**
449 * Decide whether the inactivity backstop should reap the daemon right now.

Callers 1

startMethod · 0.95

Calls 4

backstopShouldExitMethod · 0.95
stopMethod · 0.95
reapDeadClientsMethod · 0.95
resolveClientSweepMsFunction · 0.85

Tested by

no test coverage detected