* Drop every connected client whose peer process is gone. Returns the count * reaped. `isAlive` is injected for testing. Clients with unknown pids (no * client-hello) are skipped — they rely on the socket-close path.
(isAlive: (pid: number) => boolean)
| 482 | * client-hello) are skipped — they rely on the socket-close path. |
| 483 | */ |
| 484 | reapDeadClients(isAlive: (pid: number) => boolean): number { |
| 485 | if (this.clients.size === 0) return 0; |
| 486 | let reaped = 0; |
| 487 | for (const session of [...this.clients]) { |
| 488 | const peers = this.clientPeers.get(session); |
| 489 | if (!peers || !peerIsDead(peers, isAlive)) continue; |
| 490 | process.stderr.write( |
| 491 | `[CodeGraph daemon] Reaping client with dead peer (pid ${peers.pid}); clients=${this.clients.size - 1}.\n` |
| 492 | ); |
| 493 | try { session.stop(); } catch { /* best-effort */ } |
| 494 | this.dropClient(session); |
| 495 | reaped++; |
| 496 | } |
| 497 | return reaped; |
| 498 | } |
| 499 | |
| 500 | private cleanupLockfile(): void { |
| 501 | try { |
no test coverage detected