Hi, I got a kotlin server app that is deployed in pods (k8s). In some cases, k8s can send SIGTERM / SIGKILL signals to kill my app.
What is the good way, in Kotlin, to gracefully shutdown (close all connections...)?
Is there better than the java way?
that does exactly this on top of Structured Concurrency.
So, if you receive a
SIGTERM
or
SIGINT
it will
cancel
the
CoroutineScope
, and it'll block the shutdown thread until the entire program is finished (
CoroutineScope.join
).
This allows you to run finalisers, such as committing offsets to Kafka,
stop(500, 500)
any network engine, clean-up, etc.
Side-note: it lives under the Arrow-kt umbrella, but it only has KotlinX Coroutines as a dependency.
https://github.com/arrow-kt/suspendapp
👍🏾 1
gratitude thank you 1
👍 2
e
Emil Kantis
06/21/2024, 3:22 PM
You should watch Simon’s excellent video on the topic as well. I can’t find it now sadly
👍🏾 1
s
simon.vergauwen
06/22/2024, 8:02 AM
I think you're referring to this one @Emil Kantis,