Skip to content

Close client connections on SIGINT/SIGTERM #2964

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

Merged
merged 2 commits into from
Oct 30, 2016

Conversation

kulshekhar
Copy link
Contributor

Fixes #2875

Currently, express doesn't shut down immediately after receiving SIGINT/SIGTERM if it has client connections that haven't timed out. (This is a known issue with node)

This PR intends to fix this behavior such that parse server will close all open connections and initiate the shutdown process as soon as it receives a SIGINT/SIGTERM signal.

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

1 similar comment
@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

One small nit but that should do.
Could you add the link to the node-js issue around for posterity

@@ -43,8 +47,27 @@ function startServer(options, callback) {
}
ParseServer.createLiveQueryServer(liveQueryServer, options.liveQueryServerOptions);
}

function initializeConnections(socket) {
const socketId = socket.remoteAddress + ':' + socket.remotePort
Copy link
Contributor

Choose a reason for hiding this comment

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

Add trailing:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like this?

  function initializeConnections(socket) {
    /* Currently, express doesn't shut down immediately after receiving SIGINT/SIGTERM if it has client connections that haven't timed out. (This is a known issue with node - https://github.com/nodejs/node/issues/2642)

      This intends to fix this behavior such that parse server will close all open connections and initiate the shutdown process as soon as it receives a SIGINT/SIGTERM signal. */

    const socketId = socket.remoteAddress + ':' + socket.remotePort;

@facebook-github-bot
Copy link

@kulshekhar updated the pull request - view changes

@flovilmart
Copy link
Contributor

Awesome!

@flovilmart flovilmart merged commit 4a2f7ff into parse-community:master Oct 30, 2016
@kulshekhar kulshekhar deleted the pg-ctrl-c-hang branch October 30, 2016 16:00
@mmarshak
Copy link

@flovilmart I integrated a job scheduler in the same server that Parse server use, I am using Kue-Scheduler. In order to prevent stuck jobs with Kue I had my own code that detect when there is SIGINT/SIGTERM and does a clean shutdown of Kue (radis based connection) by calling -

Queue.shutdown( shutDownTimout, function(err){
console.log("Kue Shutdown completed result ", err || "ok" );
process.exit(0);
}

Now Parse handing of SIGINT/SIGTERM is independent of Kue handling of shutdown and one can decided to exist earlier before the other.

It will be very helpful if there was some hook (function) that Parse server will before it actually call process.exit() and allow other connections to close cleanly before Parse call exit().

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.

Server doesn't shut down with Ctrl+C
4 participants