Skip to content
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

Terminate the workers more gracefully #151

Closed
wants to merge 2 commits into from

Conversation

Pchelolo
Copy link
Contributor

@Pchelolo Pchelolo commented Feb 17, 2017

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

if (Array.isArray(self.serviceReturns)) {
return P.each(self.serviceReturns, function(serviceRet) {
stoppers = P.each(self.serviceReturns, function(serviceRet) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we expect each service to implement a graceful shutdown independently, then we should probably start all those in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye, that's a good idea, why not..

@Pchelolo
Copy link
Contributor Author

@gwicke I'd like to put the PR on hold now. You're making a good point about shutting things down under the feet of running requests, lemme try to see if we can avoid that problem and do better.

@gwicke
Copy link
Member

gwicke commented Feb 17, 2017

Looking at https://nodejs.org/api/http.html#http_server_close_callback, we might actually be fine if each service is careful to implement its own graceful shutdown, starting with a close() and followed by a timeout. That's not the case right now though, so we'd need to first implement that carefully in all services.

@Pchelolo
Copy link
Contributor Author

@gwicke Another thing here is that we don't really call this all when the service is stopped in production, right now this is only called in tests. So it would be nice to make prod do this too.

@Pchelolo Pchelolo closed this Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants