Graceful Shutdown
250bpm.com
250bpm.com
Quickly you find out that recording the list of process / task / ... , including the relationship between each is a useful thing to have. With that first-class registry, it's possible to implement all sorts of shutdown and restart logics.
But the question here is not whether you can implement different kinds of shutdown, it's rather which kind covers the common graceful shutdown use cases.
If Erlang/OTP has such algorithm, I'd love to hear about it.
The right thing to do in this case is for the server to also disconnect any websockets when it gets the SIGTERM, in addition to stopping the accept loop and the other things it would normally do. Clients simply have to reconnect (and have enough tolerance in the socket's in-band protocol to recover state, roll back transactions, etc.) It's a scenario that's bound to happen to a certain percentage of your clients anyway, due to all sorts of external factors, and must be handled regardless.
I have spent numerous hours on figuring out how to shut down multi threaded desktop apps within reasonable time. It’s not easy.
In Go, you can keep track of deadlines using a Context [1]. Subrequests also need to know the deadline (or perhaps a shorter deadline), so they get passed a derived context. The same mechanism also supports cancellation.
https://github.com/golang/go/issues/29011
If you are interested in that you may want to participate.
It allowed me to implement zero downtime upgrades, which was pretty cool. Internally within the agent, I used the context pkg to implement with a 'Manager' which provided cron like functionality where each thing could be shutdown gracefully [3]. Used the same mechanism to shut the internal webserver down gracefully as well [4].
[1] https://github.com/jpillora/overseer
[2] https://github.com/blockassets/bam_agent
[3] https://github.com/blockassets/bam_agent/blob/f7edce599b770b...
[4] https://github.com/blockassets/bam_agent/blob/f7edce599b770b...
https://kotlinlang.org/docs/reference/coroutines/cancellatio...