fix: graceful ctrl+c shutdown and await session-end memory writes
This commit is contained in:
@@ -564,11 +564,14 @@ export class GatewayServer {
|
||||
}
|
||||
}
|
||||
|
||||
// Close all WebSocket connections first
|
||||
// Close all WebSocket connections first.
|
||||
// Await disconnects so end-of-session summary/memory writes complete before process exit.
|
||||
const disconnects: Array<Promise<void>> = [];
|
||||
for (const [ws, connectionId] of this.connectionMap) {
|
||||
this.sessionBridge.disconnect(connectionId);
|
||||
disconnects.push(this.sessionBridge.disconnect(connectionId));
|
||||
ws.close(1001, 'Server shutting down');
|
||||
}
|
||||
await Promise.allSettled(disconnects);
|
||||
this.connectionMap.clear();
|
||||
this.connectionStateMap.clear();
|
||||
|
||||
@@ -628,7 +631,9 @@ export class GatewayServer {
|
||||
});
|
||||
|
||||
ws.on('close', () => {
|
||||
this.sessionBridge.disconnect(connectionId);
|
||||
void this.sessionBridge.disconnect(connectionId).catch((error) => {
|
||||
console.warn('Session disconnect failed:', error);
|
||||
});
|
||||
this.connectionMap.delete(ws);
|
||||
this.connectionRateMap.delete(connectionId);
|
||||
this.connectionStateMap.delete(connectionId);
|
||||
|
||||
Reference in New Issue
Block a user