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

How to achieve graceful server shutdown for environments that rely on healthcheck to mark nodes unhealthy #587

Open
niodice opened this issue May 15, 2023 · 2 comments

Comments

@niodice
Copy link

niodice commented May 15, 2023

Background Context

I'm working in a hosting environment that at a high level works like this:

  • Load balancer monitors /health endpoint, exposed via admin port, to identify if hosts are healthy and routable.
  • If the health check fails for an instance some number of times in a row, the service is marked as unlealthy and traffic will not be routed to that instance.
  • During deployments or instance replacements, a SIGTERM is sent to the service to trigger a shutdown.

Observed behavior

Pain points

  • This is problematic because there is a period of time where:
    • The admin server has shut down and won't report healthy
    • The application server has shut down and won't accept any requests
    • The load balancer is still routing traffic to this instance because there needs to be > 1 occurrence of a failed health check before the instance is taken out of rotation. These requests fail. It is not always safe to retry these requests because they may not be idempotent.

Desired behavior

  • Is there a way to have fine control over the shutdown sequence? Ideally, I would:
    • Shut down admin server (or tell admin server to report a non 200 status code) and keep the application server up for a configurable amount of time, say 15 seconds)
    • After some period of time, shutdown the application server and then gracefully terminate the program.
@niodice
Copy link
Author

niodice commented May 15, 2023

@cacoco
Copy link
Contributor

cacoco commented Aug 17, 2023

@niodice using the SIGTERM (as opposed to calling close() on the server) is going to bypass a lot of the graceful shutdown mechanics, IIRC.

The most straightforward thing to do, likely is to handle the interrupt using c.t.util.HandleSignal and then call close().

See: https://twitter.github.io/finatra/user-guide/app/index.html#an-example-of-handling-signals (note a TwitterServer is an App, so you can follow the example similarly somewhere in your Server definition)

You likely also want to mess with the grace period in the server as well if necessary to allow for more time for closing resources if necessary. Hope that helps.

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

No branches or pull requests

2 participants