process.on('SIGINT', () => { console.log("SIGINT received. Performing clean shutdown..."); // Implicitly calls server.close, then disconnects the IPC channel: cluster.worker.disconnect(); });
async checkConnectionLeak() { const timeoutID = setTimeout(() => { log.error('Redis connection leak detected'); Metric.observeRedisLeak(); this.worker.disconnect(); setTimeout(() => { this.worker.kill(); }, this.options.heartBeatStanch * 1000); }, this.options.heartBeatTimeout * 1000); try { await this.ping(); log.debug('Redis pong'); timeoutID.close(); } catch (err) { log.error('Redis error: ', err.message); timeoutID.close(); } }
}); worker.disconnect();
//signal of workers restart process.on("SIGUSR2", () => { const workers = Object.keys(cluster.workers); console.log("workers: ", workers); //recursive function over workers const restartWorker = workerIndex => { if (workerIndex >= workers.length) return; const worker = cluster.workers[workers[workerIndex]]; console.log(`Stopping worker: ${worker.process.pid}`); worker.disconnect(); // disconnect task worker.on("exit", () => { if (!worker.exitedAfterDisconnect) return; // when the worker was disconnected we can start a new one const newWorker = cluster.fork(); newWorker.on("listening", () => { // once the new worker is listerning we can restart the next worker restartWorker(workerIndex + 1); }); }); }; restartWorker(0); });
}); }); worker.disconnect(); return res;
function stop() { shouldStop = true; if (!started) { return; } if (stopping) { return; } stopping = true; console.log('stopping'); if (process.argv[2] === 'listen') { server.close(doStop); } else { doStop(); } function doStop() { if (!process.connected) { process.exit(0); } if (cluster.worker) { cluster.worker.disconnect(); } else { process.disconnect(); } } }
cluster.worker.disconnect(); }, 1000);
worker.send(config) worker.on('message', data => { worker.disconnect() handler(t, data) })
//signal of workers restart process.on("SIGUSR2", () => { const workers = Object.keys(cluster.workers); console.log("workers: ", workers); //recursive function over workers function restartWorker(i) { if (i >= workers.length) return; const worker = cluster.workers[workers[i]]; console.log(`Stopping worker: ${worker.process.pid}`); worker.disconnect(); // disconnect task worker.on("exit", () => { if (!worker.exitedAfterDisconnect) return; // when the worker was disconnected we can start a new one const newWorker = cluster.fork(); newWorker.on("listening", () => { // once the new worker is listerning we can restart the next worker restartWorker(i + 1); }); }); } restartWorker(0); });