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

[Issue #7] Add support for graceful shutdowns. #21

Merged
merged 8 commits into from Dec 9, 2013
Merged

[Issue #7] Add support for graceful shutdowns. #21

merged 8 commits into from Dec 9, 2013

Conversation

sean
Copy link
Contributor

@sean sean commented Nov 24, 2013

With this change hitting Control+C or sending kill -{2,15} (SIGINT or SIGTERM) will cause the server to shutdown gracefully draining any connections. Clients which connect will see this message:

Server is in the process of restarting.

If the connections are drained successfully prior to the timeout, stdout will display:

Received kill signal, shutting down gracefully.
Closed out remaining connections.

and the exit code will be 0. Otherwise you'll see:

Received kill signal, shutting down gracefully.
Could not close connections in time, forcefully shutting down.

and the exit code will be 1. The timeout is hardcoded at 30s, perhaps this should be configurable.

@totherik
Copy link
Member

Although I don't have time to review this right this second, I'm not ashamed to say I want to hug you for contributing this, and so quickly. Thanks @sean!

Update Application Life Cycle Docs
@jeffharrell
Copy link
Member

Awesome 👍

Shouldn't the server return a 503 instead of a 502 in this case? Also, either as part of this or as a subsequent commit we should enable a template to be loaded from middleware:errorPages

return next();
}
res.setHeader("Connection", "close");
res.send(502, "Server is in the process of restarting.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with the team.
Thanks!
Just one very minor nitpick:
Should say "shutting down" instead of restarting.

@sean
Copy link
Contributor Author

sean commented Nov 25, 2013

Good catch, that was a typo, I've corrected it in the most recent patch. Now it sets a status of 503 (Service Unavailable) and renders the errorPages['503'] template if defined.

res.status(503);
res.render(template);
} else {
res.send(503, "Server is in the process of restarting.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with the team.
Thanks!
Just a minor nitpick on this line: Should it say "shutting down" instead of "restarting"?

@totherik
Copy link
Member

Thanks @sean. Just a few nitpicks/thoughts.

In index.js can you please either 1) move the httpServer variable declaration to the top of the function to match coding style, or 2) inline the call: app.set('kraken:server', server.listen(port, host));?

I see there's mixed single and double quotes in some places. The coding style for kraken-js is single quotes everywhere.

Should the kraken config object support more generic states? e.g kraken:state could be set to disconnected, listening, disconnecting, etc. Would there be value in that over a single binary state or is it not worth the complexity of transitioning states?

I know we don't (yet) have logging integrated into kraken, but can you please remove the console.log statements? I'm thinking that in addition to logging we should support debuglog, and maybe these statements could use that in the interim. Either way, I'm doing my best to resist the temptation to have a module write unwanted stuff to folk's stdout/stderr.

Can we make the shutdown-timeout configurable with 30 seconds as a default?

@sean
Copy link
Contributor Author

sean commented Nov 27, 2013

@totherik I've incorporated all of the review feedback and the pull request has been updated. Thanks!

@jeffharrell
Copy link
Member

Two more nitpicks and then I think we're good:

  1. +1 to Erik's idea about using kraken:state=disconnecting rather than kraken:shuttingDown=true. The former is a tad more flexible.
  2. The default config value should be populated and taken from https://github.com/sean/kraken-js/blob/master/config/webcore.json . Also, it should be camelCase and not use underscores. The user config is merged with this file on startup, so the defaults are implied if nothing overrides them.

@lmarkus
Copy link
Contributor

lmarkus commented Dec 6, 2013

I like it 👍

@jeffharrell
Copy link
Member

Thanks for the work, @sean. I filed #60 to track that we should add additonal values to the kraken:state value, but otherwise this is good to go.

jeffharrell added a commit that referenced this pull request Dec 9, 2013
[Issue #7] Add support for graceful shutdowns.
@jeffharrell jeffharrell merged commit 26e91eb into krakenjs:master Dec 9, 2013
@sean
Copy link
Contributor Author

sean commented Dec 10, 2013

Thanks @jeffharrell!

t0lkman pushed a commit to t0lkman/kraken-js that referenced this pull request Feb 6, 2014
Missed reference to old webcore-appsec
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.

None yet

5 participants