-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd: ensure http servers shut down gracefully #262
Conversation
Codecov Report
@@ Coverage Diff @@
## master #262 +/- ##
==========================================
+ Coverage 62.14% 62.18% +0.04%
==========================================
Files 53 54 +1
Lines 4166 4197 +31
==========================================
+ Hits 2589 2610 +21
- Misses 1390 1399 +9
- Partials 187 188 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes/Qs for reviewers!
@jphines thanks for the feedback, I think I've addressed all your comments.
So I did add some tests, please let me know what you think of the approach I took. In short, in the unit tests we redefine the set of shutdown signals that Note, though, the giant dumb caveat here, explaining why this doesn't perfectly test the behavior, and why I'm not sure the extra complexity to perfectly test it is worth it: sso/internal/pkg/httpserver/httpserver_test.go Lines 49 to 76 in 1bf00ac
|
@mccutchen I agree with that the additional complexity necessary to "properly" test the signal handling doesn't seem worth it at this point in time. This seems reasonable to land as-is. Thank you so much for the contribution, this is a great changeset. 💯 🚀 |
1bf00ac
to
5e4a232
Compare
Problem
Both
sso-proxy
andsso-auth
abort all in-flight requests on shutdown. Instead, they should stop accepting new requests and allow in-flight requests to complete before exiting.Addressing this will make deploys of the sso services less disruptive to end users.
Solution
Because graceful shutdown is just tricky enough to get right, here we add a new internal
httpserver
package that exposes a single function,Run()
, which will run an http server and arrange for graceful shutdown when receivingSIGTERM
orSIGINT
. A shutdown timeout must also be provided, after which the server will abort any outstanding requests.Notes
Reproducing
The easiest way I know to reproduce the behavior uses httpbin via the quickstart:
docker-compose up -d
to bring up the demo services-t 30
to tell docker to wait up to 30 seconds before forcibly killing it):On latest master, you should immediately get an HTTP 502 error.
With these changes, you should instead get a successful response after the 9 seconds have elapsed, and then sso-proxy will be shut down.
Unit tests
I'm not entirely sure how to test this, given that
SIGTERM
orSIGINT
, andhttpserver.Run()
interface manages the whole lifecycle of the server, leaving no straightforward way to control the listener or figure out what port it is listening on (assuming we'd want it to choose a random available port)If anybody has any good ideas for tackling (1) I'm all ears; the issues in (2) are under our control, so we could conceivably make the interface more flexible and use a trick like this to choose a random port in advance (though this would be inherently race-y).
I'll also leave a few notes inline below.