✨ Simplify arrow function syntax and remove unnecessary whitespace in graceful shutdown utility
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Graceful Shutdown Handler
|
||||
*
|
||||
*
|
||||
* Handles server shutdown gracefully by:
|
||||
* - Closing server to stop accepting new connections
|
||||
* - Waiting for existing connections to finish
|
||||
@@ -25,7 +25,7 @@ export function setupGracefulShutdown(server, options = {}) {
|
||||
const connections = new Set();
|
||||
|
||||
// Track all connections
|
||||
server.on('connection', (connection) => {
|
||||
server.on('connection', connection => {
|
||||
connections.add(connection);
|
||||
connection.on('close', () => {
|
||||
connections.delete(connection);
|
||||
@@ -54,7 +54,7 @@ export function setupGracefulShutdown(server, options = {}) {
|
||||
// Set shutdown timeout
|
||||
const shutdownTimeout = setTimeout(() => {
|
||||
logger.error(`Shutdown timeout (${timeout}ms), forcing exit`);
|
||||
connections.forEach((conn) => conn.destroy());
|
||||
connections.forEach(conn => conn.destroy());
|
||||
process.exit(1);
|
||||
}, timeout);
|
||||
|
||||
@@ -67,16 +67,16 @@ export function setupGracefulShutdown(server, options = {}) {
|
||||
|
||||
// Wait for all connections to close
|
||||
logger.info(`Waiting for ${connections.size} connections to close...`);
|
||||
|
||||
|
||||
// Close all idle connections
|
||||
connections.forEach((conn) => {
|
||||
connections.forEach(conn => {
|
||||
if (!conn.destroyed) {
|
||||
conn.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Give connections time to finish
|
||||
await new Promise((resolve) => {
|
||||
await new Promise(resolve => {
|
||||
const checkInterval = setInterval(() => {
|
||||
if (connections.size === 0) {
|
||||
clearInterval(checkInterval);
|
||||
@@ -97,7 +97,7 @@ export function setupGracefulShutdown(server, options = {}) {
|
||||
|
||||
// Register shutdown handlers for various signals
|
||||
const signals = ['SIGTERM', 'SIGINT', 'SIGUSR2'];
|
||||
signals.forEach((signal) => {
|
||||
signals.forEach(signal => {
|
||||
process.on(signal, () => shutdown(signal));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user