Terminate the workers more gracefully #151
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously our shutdown process only closed the http server, and we never actually close anything else that might need to be closed within the server if the num_workers was > 0. The procedure described here would basically do the same thing for the HTTP servers as done right now by disconnect, but additionally it would provide us a way to hook into the disconnection process and close whatever the services requested.
We could've done that by adding a listener in the worker for the disconnect event, but, that's problematic because the service-provided closing handler should explicitly close the HTTP server for the num_workers === 0 case and then with num_workers > 0 case calling the service-provided close method fails because the server was already killed by the cluster module.
Also, this is more in line with what the official docs say: https://nodejs.org/dist/latest-v6.x/docs/api/cluster.html#cluster_worker_disconnect
Bug: https://phabricator.wikimedia.org/T158265
cc @wikimedia/services