Just wondering if I am over-engineering the application shutdown by manually closing other service connections.
This is what I am currently doing. Is there a benefit of calling DB.Close or REDIS.Close at all? I mean the HTTP server is shutdown so I believe all the other services will be killed automatically. Am I right?
Closing connections to external resources manually will usually enforce clean disconnection and also wait for other go-routines still writing to the socket, while a hard exit will indeed close the connection, but the external service might take a while to realise it due to timeouts or currently running transactions might be canceled/rollbacked.
@NobbZ Thanks for the prompt answer and explanation. One last thing to clarify, since the HTTP shutdown is listening on certain OS signals in order to gracefully shutdown the server, I believe manually closing external resources to enforce clean disconnection, as you said, is an ideal way of doing things. Am I correct to assume this?
Besides the fact that is a good practice to clean up after you, in your particular case, using Redis seems that is mandatory to do this beacause you can’t be sure if the database have a timeout or not.
By default recent versions of Redis don’t close the connection with the client if the client is idle for many seconds: the connection will remain open forever.
However if you don’t like this behavior, you can configure a timeout, so that if the client is idle for more than the specified number of seconds, the client connection will be closed.