feat: wire graceful shutdown for shard connections on SIGTERM/SIGINT

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-20 11:27:58 -04:00
parent 3c1d5b2224
commit 9c9927218a

View File

@@ -4,6 +4,7 @@ const http = require('http');
const cors = require('cors');
const { bootstrapGames } = require('./bootstrap');
const { WebSocketManager, setWebSocketManager } = require('./utils/websocket-manager');
const { cleanupAllShards } = require('./utils/ecast-shard-client');
const app = express();
const PORT = process.env.PORT || 5000;
@@ -53,6 +54,15 @@ if (require.main === module) {
console.log(`Server is running on port ${PORT}`);
console.log(`WebSocket server available at ws://localhost:${PORT}/api/sessions/live`);
});
const shutdown = async () => {
console.log('Shutting down gracefully...');
await cleanupAllShards();
server.close(() => process.exit(0));
};
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
}
module.exports = { app, server };