-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worker disconnect is not waiting for server closing #1305
Comments
Is this really the expected behaviour? Disconnecting the master/worker IPC channel is independent from anything else. If you want to close the server (and gracefully terminating the worker), when the master disconnects the IPC channel, you have to implement it: cluster.worker.on('disconnect', function() {
console.log('Worker disconnected, closing server');
server.close();
});
var server = ...; |
I think disconnect is independent when we talking about child and parent. But if it is all about cluster, disconnect only then all servers is closed is very useful from my point of view. Anyway, this behavior is described in docs. Or I get it wrong? |
Also, in cluster, disconnect already causing servers to close. But you can't detect if all connections is done. |
Sorry, my answer was not correct - you are right, the But: In your implementation the IPC channel is really closed immediately, so the "Cluster: worker is disconnected" is correct, and the master has no chance to notice when the server is closed (except from listening to the "exit" event, when the child process exits). The better implementation would be:
One more advantage with this implementation: You can send additional status messages between master and worker even while shutting down :-) |
@not-implemented Why it is correct?
I understand
So I expect the following:
And the things are really working this way (as seen from cluster.js implementation), besides waiting for all servers to close. By the way, the Concerning examples, |
Hmm ... ok, I see :-) ... It's not implemented as documented. Any implementation like I thought I can help you here ... but I always used the cluster the other way round, and initiated the disconnect from the worker side. |
@not-implemented |
@not-implemented for now, I don't know how to handle server.close() in case of round-robin distribution. |
Before this, cluster behaves not the way it is documented. When disconnect is triggered, worker must wait for every server is closed before doing disconnect actually. Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: nodejs#1400 Fixes: nodejs#1305
fixed by #1400 |
Demo app: https://gist.github.com/Olegas/c2e5550911cbe8b96dae
Steps to reproduce
telnet localhost 8080
Disconnecting worker
andCluster: worker is disconnected
to appearExpected behavior:
Cluster: worker is disconnected
message until all connections is closed (https://iojs.org/api/cluster.html#cluster_worker_disconnect "... wait for the 'close' event on those servers ... ")Server is closed
message in the log (from line 32)The text was updated successfully, but these errors were encountered: