Closed brotskydotcom closed 8 years ago
If you google for "golang server graceful shutdown," you will find both a lot of approaches for how to do this (including sample code) and some existing published web frameworks which make it easy. I would prefer not to go the "external framework route" yet, but I could be convinced otherwise.
Actually I am not convinced this is needed. Now that we have session persistence (#11), the better way to handle this is probably just to bring up the different server and route traffic to it and then kill the server abruptly. The one thing it might be worth doing would be to close connections when requests completed, so there wouldn't be the chance for a client to submit another request on the existing connection.
it looks like the go HTTP library Hijack mechanism allows response handlers to seize their connection and close it. So that looks like the easy way to shut down "gracefully", should that become necessary. For now, I'm going to close this as low priority.
When the server receives a SIGTERM, it simply quits hard, rather than stopping listening for new connections and waiting for the existing requests in progress to complete. It should shut down gracefully.