* 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
()
| 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. |
no test coverage detected