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
Calling disconnect causes processes spawned by cluster module to exit too early #27679
Comments
Sorry, I ran out of time to look at this, but what I suspect is happening is that the master does not expect to see the IPC pipe closed directly, without the worker sending a message saying that it is going to do so, considers this to be unexpected, and kills the worker. I had trouble proving that, though, more research would be required. Note that using |
@sam-github |
Apologies, I meant The cluster modules is not very flexible, if its not being used for exactly the intended use-case (identical net or http servers), its features easily become misfeatures, so using child_process is probably a better idea for you. |
Just ran into a variation of this issue, in our case the master process exits and we want to perform some proper graceful shutdown on the child processes. Happy to contribute, but want to validate that I have the correct approach first. I believe the root cause of both issues (master process going away and The approach that I think would solve this issue would be to add an option (similar to |
Is anyone working on this I would be interested in looking into it. I may need some guidance but I am willing to give it a shot. |
Based on the documentation I believe process.disconnect is working correctly and as expected. @sam-github makes a good point about the cluster module flexibility. Using the cluster module effectively requires the usage of worker.disconnect to handle graceful shutdown*. This has been surprising behavior to people since 2016[1][2]. I'm not convinced that a change to either the cluster or the child_process modules are needed. The 2017 issue[2] suggested updating the documentation to make this behavior clear; however, the documentation does not appear to have been changed. I've created a PR for updating the documentation #38713 [1] #13671
|
Consider the following script:
When
useCluster
istrue
node exits immediately and nothing is printed to the console. WhenuseCluster
isfalse
you see "hi from worker" logged after 1s and then node will exit which is the expected behavior. The documentation makes it sound like callingprocess.disconnect
should only close the IPC channel between the master and worker process and should not cause either to exit early if there is still work to do.The text was updated successfully, but these errors were encountered: