WIP: fix graceful shutdown, add SIGTERM handler #1951
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An attempt to address issue #1946
👍 Adds signal handling for SIGTERM
👍 Allows graceful shutdown to complete (instead of HTTP requests in-flight being terminated suddenly)
👎 doesn't allow time for in-flight requests to finish. The context is cancelled for each in-flight request as a side-effect of the way servers shutdown and a parent context is cancelled. I can't see a way to get this to work as I'd like, so opening this draft PR for suggestions or discussion.
I believe the code flow is now:
down.Shutdown(tctx)
, causing each server to stop listening for new requests, and immediately returnhttp.ErrServerClosed
from theirServe()
orListenAndServe()
callssrvs.Wait()
immediately completes for the server ErrorGroup, cancelling it's contextsrvctx
srvctx
is a parent of each http request's context, so each in-flight request begins context-cancellation processingI tried not having all request contexts children of
srvctx
, but got lots of context-related warnings logged frompkg/ctxlock/ctxlock.go
during graceful shutdownIn practice this changes the behaviour seen when clair does a graceful shutdown -
From:
To: