if we set up pm2 to resurrect on failure, this causes the unexpected resurrection of the killed/deleted/stopped processes.
Based on this thread I think it is related to a synchronization error when multiple processes are closed at once. I was also able to delete the processes one by one without any problem.
I could mitigate the error adding a callback to handle the exception:
cluster.on("exit", (worker) => {
// notify all active workers
for (const workerId in cluster.workers) {
if (hasOwnProperty.call(cluster.workers, workerId)) {
cluster.workers[workerId].send({
source: MESSAGE_SOURCE,
type: EventType.WORKER_EXIT,
data: worker.id,
}, (err) => {
if (err) {
if (err.code == 'ERR_IPC_CHANNEL_CLOSED' || err.code == 'EPIPE') {
console.warn(`There was a synchronization problem. Wrong attempt to send a message to a disconnected worker`)
console.log(err);
} else {
throw err;
}
}
});
}
}
});
Hey! Nice work! I found an issue when I try to run a process in cluster mode using this library.
Description
When I run a process in cluster mode using the
@socket.io/pm2
library and I try to delete them usingpm2 delete all
I get the following errors:It seems on exit it is trying to send the
WORKER_EXIT
message to disconnected workers.https://github.com/socketio/socket.io-cluster-adapter/blob/43f9ee8d23d2a4bc72ce4399c0b2b8445360f8cc/lib/index.ts#L579-L590
if we set up pm2 to resurrect on failure, this causes the unexpected resurrection of the killed/deleted/stopped processes.
Based on this thread I think it is related to a synchronization error when multiple processes are closed at once. I was also able to delete the processes one by one without any problem.
I could mitigate the error adding a callback to handle the exception:
Steps to reproduce
let i = 0;
async function run() { while (true) { await new Promise(resolve => setTimeout(resolve, 5000)); console.log(
Number ${i++}.
); } }run().catch(error => { console.error('Error!', error); process.exit(); });
After doing this, you will see the exceptions.
Env details