* Detach the WebSocket from a session and start the grace period timer. * After `gracePeriodMs` with no reconnect, `onExpire` is called and the * session is destroyed.
(token: string, onExpire: () => void)
| 94 | * session is destroyed. |
| 95 | */ |
| 96 | startGrace(token: string, onExpire: () => void): void { |
| 97 | const session = this.sessions.get(token); |
| 98 | if (!session) return; |
| 99 | |
| 100 | session.ws = null; |
| 101 | session.lastActive = new Date(); |
| 102 | |
| 103 | if (session.graceTimer) { |
| 104 | clearTimeout(session.graceTimer); |
| 105 | } |
| 106 | |
| 107 | const remainingSec = Math.round(this.gracePeriodMs / 1000); |
| 108 | console.log( |
| 109 | `[session ${token.slice(0, 8)}] Disconnected — grace period: ${remainingSec}s`, |
| 110 | ); |
| 111 | |
| 112 | session.graceTimer = setTimeout(() => { |
| 113 | session.graceTimer = null; |
| 114 | console.log( |
| 115 | `[session ${token.slice(0, 8)}] Grace period expired — cleaning up`, |
| 116 | ); |
| 117 | this.destroy(token); |
| 118 | onExpire(); |
| 119 | }, this.gracePeriodMs); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Immediately kill the PTY and remove the session. |
no test coverage detected