* Decide whether the inactivity backstop should reap the daemon right now. * Public + `isAlive`-injected for deterministic tests; the timer calls it each * tick with the real liveness probe. * * The backstop exists ONLY to catch a **phantom** client (#692) — one counted * but actually
(isAlive: (pid: number) => boolean)
| 465 | * client keeps the daemon up. Has the sweep's side effect (drops dead peers). |
| 466 | */ |
| 467 | backstopShouldExit(isAlive: (pid: number) => boolean): boolean { |
| 468 | if (this.stopping || this.clients.size === 0) return false; // idle timer owns the no-client case |
| 469 | if (Date.now() - this.lastActivityAt < this.maxIdleMs) return false; // still within the window |
| 470 | this.reapDeadClients(isAlive); |
| 471 | if (this.clients.size === 0) return false; // sweep cleared them — idle timer takes over |
| 472 | const anyProvablyAlive = [...this.clients].some((session) => { |
| 473 | const peers = this.clientPeers.get(session); |
| 474 | return peers != null && peers.pid !== null && !peerIsDead(peers, isAlive); |
| 475 | }); |
| 476 | return !anyProvablyAlive; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Drop every connected client whose peer process is gone. Returns the count |
no test coverage detected