twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 405 forks source link

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

Open niodice opened 1 year ago

niodice commented 1 year ago

Background Context

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

Observed behavior

Pain points

Desired behavior

niodice commented 1 year ago

Also posted in gitter: https://matrix.to/#/!fqPdgWhOEtxbPlasve:gitter.im/$skWDihqObMBVhErRuXgkeqIploCBKlZWmiria1xpVAg?via=gitter.im&via=matrix.org

cacoco commented 1 year ago

@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.