Ran Magen
11/19/2019, 12:19 AMSIGTERM
.
I can implement this myself, though if there's already a commonly used feature, I'd opt to not re-invent the wheel.
My general idea is to set some boolean like stopRequested
when getting a SIGTERM
and maintain another var active: Int
with the current number of active requests similar to https://github.com/ktorio/ktor/blob/master/ktor-features/ktor-metrics/jvm/src/io/ktor/metrics/dropwizard/DropwizardMetrics.kt#L22
so when that number hits 0 and stopRequested
is true, only then finish the process.SIGTERM
and have some graceful shutdown time. Right now they die while requests are in flight and we see a dip in success rate.server.stop
should suffice? we have them set to
server.stop(gracePeriod = 10, timeout = 10, timeUnit = SECONDS)
Hm I'll go back to this. Maybe this is more of a k8s problem sending requests to the pod after the SIGTERM or maybe we have some very slow requests.napperley
11/19/2019, 3:13 AMRan Magen
11/19/2019, 7:11 PMRuntime.getRuntime().addShutdownHook
napperley
11/19/2019, 11:30 PMRan Magen
11/19/2019, 11:41 PMfun onShutdown(action: () -> Unit) =
Runtime.getRuntime().addShutdownHook(Thread(action))