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

[FEATURE] wait-ready for shutdown #2979

Open
shaunwarman opened this issue Jun 28, 2017 · 5 comments
Open

[FEATURE] wait-ready for shutdown #2979

shaunwarman opened this issue Jun 28, 2017 · 5 comments

Comments

@shaunwarman
Copy link

shaunwarman commented Jun 28, 2017

The wait-ready property is extremely useful. It would be great to have a similar option for a worker to send a message to pm2 telling it to explicitly kill itself. The benefit here is pm2 knows not to send connections/requests and to give the worker some time to gracefully shutdown. This is best used for uncaughtException, unhandledRejection use cases.

Example:

// worker
process.on('uncaughtException', () => {
  process.send('shutdown', options);
});

// pm2
process.on('message', (msg, options) => {
  if (msg === 'shutdown') {
    worker.kill('SIGINT');
    // let worker cleanup and exit itself
  }
});

// worker
process.on('SIGINT', () => {
  // ... cleanup
  process.exit(1);
}); 

What I really want to eliminate here is the node/worker process closing server, cleaning up and gracefully shutting down while pm2 doesn't yet know that worker is attempting to shutdown because of some uncaught exception unknown to parent process (pm2).

@Unitech
Copy link
Owner

Unitech commented Jul 2, 2017

would you be courageous enough for a PR? ;)

@shaunwarman
Copy link
Author

Sure, what do you think about the idea?

I know it's common place to exit, but the thought of lingering in flight requests without at least a header thrown back out with 503 or similar makes me uncomfortable.

@Unitech
Copy link
Owner

Unitech commented Jul 4, 2017

After thinking a bit about this, disabling new incoming queries to a specific worker is not possible right now as we are using the cluster module to handle lb. Maybe it's possible to interface with the cluster module to do that but it requires some deeper inspection.
This feature could make a lot of sense in the new external load balancer interface we plan to put on PM2 v3 #2995

@shaunwarman
Copy link
Author

Sounds good 👍 - is there a branch or discussion? Maybe I can contribute towards that instead.

@shaunwarman
Copy link
Author

shaunwarman commented Sep 19, 2017

Mainly in reference to #2995 - but any update or timeline for pm2 v3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants