Closed wvhulle closed 1 year ago
Adding app.close() in the workers does not seem to help.
But adding this in the primary
cluster.on("exit", (worker) => {
console.log(`Worker ${worker.process.pid} died`);
if (Object.values(cluster.workers).length === 0) {
httpServer.close()
}
});
solves the problem, but maybe this library should also have something opposite to setupMaster? Like closeMaster? Or otherwise be able to deal with data still coming in the primary server but no workers available.
cluster.on("exit", (worker) => {
console.log(`Worker ${worker.process.pid} died`);
if (Object.values(cluster.workers).length === 0) {
httpServer.prependListener("connection", (socket) => { socket.destroy() })
}
});
Also seems to work.
@wvhulle I could indeed reproduce, thanks. We should definitely handle the case where there are no available worker.
Should I open a merge request with one of my fixes?
That would be awesome 👍
For future readers:
This should be fixed by https://github.com/socketio/socket.io-sticky/commit/e8b4203d18fc9601e05af3457baba49fafdb15f0, included in version 1.0.3. Please reopen if needed!
Thanks a lot!
There is a problem with the function computeWorkerId when express is used to construct the socket io server. When all the socket worker servers have been closed, the following error appears:
It seems like the function cannot deal with the case where there are no workers. When I remove express, the problem disappears.
The bug can be seen in https://github.com/wvhulle/socket.io-fiddle/tree/cluster-adapter, after running the client and the server, then waiting until the worker threads quit.