-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat: graceful shutdown #1963
feat: graceful shutdown #1963
Conversation
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
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.
Thanks @nabokihms !
I had a few requests, but it's great to finally have graceful shutdown in Dex!
cmd/dex/serve.go
Outdated
} | ||
|
||
return <-errc | ||
sig := make(chan os.Signal) | ||
gr.Add(func() error { |
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.
The library has a builtin signal actor, maybe we could use it.
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.
Fixed. The only thing that I dislike about helper is that I can't log the received signal immediately.
cmd/dex/serve.go
Outdated
if err := l.Close(); err != nil { | ||
logger.Errorf("gracefully close (%s) listener: %v", name, err) | ||
} |
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.
AFAIK the http server takes care of this, so you don't need to call close on the listener manually.
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.
My thought was about splitting listener closing error and server shutdown error. Maybe it is excessive.
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.
Listener closing now is a duty of a server.
cmd/dex/serve.go
Outdated
if err := grpcListener.Close(); err != nil { | ||
logger.Errorf("failed to gracefully close (grpc) listener: %v", err) | ||
} |
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.
Same as above
err := http.ListenAndServe(c.Telemetry.HTTP, telemetryServ) | ||
errc <- fmt.Errorf("listening on %s failed: %v", c.Telemetry.HTTP, err) | ||
}() | ||
telemetrySrv := &http.Server{Addr: c.Telemetry.HTTP, Handler: telemetryServ} |
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.
I think defer httpServer.Close()
should be called on each server in the main func as a general cleanup step and as a last resort to graceful shutdown.
cmd/dex/serve.go
Outdated
logger.Errorf("gracefully close (%s) listener: %v", name, err) | ||
} | ||
|
||
if err := srv.Shutdown(context.Background()); err != nil { |
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.
What happens if there is an active connection for an indefinite amount of time? Will this wait indefinitely? If so, we should probably add a timeout here.
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.
Yes, good catch. I hardcoded a one-minute timeout here. Please tell me if you want to make this configurable or increase the value.
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
6687b5d
to
65a8bf2
Compare
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.
A couple small things, but overall 👍 Thanks!
Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com> Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
c5f4450
to
6664b57
Compare
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.
Thanks @nabokihms !
The official docker release for this release can be pulled from ``` ghcr.io/dexidp/dex:v2.28.0 ``` **Features:** - Add c_hash to id_token, issued on /auth endpoint, when in hybrid flow (dexidp#1773, @HEllRZA) - Allow configuration of returned auth proxy header (dexidp#1839, @seuf) - Allow to disable os.ExpandEnv for storage + connector configs by env variable DEX_EXPAND_ENV = false (dexidp#1902, @heidemn-faro) - Added the possibility to activate lowercase for UPN-Strings (dexidp#1888, @VF-mbrauer) - Add "Cache-control: no-store" and "Pragma: no-cache" headers to token responses (dexidp#1948, @nabokihms) - Add gomplate to the docker image (dexidp#1893, @nabokihms) - Graceful shutdown (dexidp#1963, @nabokihms) - Allow public clients created with API to have no client_secret (dexidp#1871, @spohner) **Bugfixes:** - Fix the etcd PKCE AuthCode deserialization (dexidp#1908, @bnu0) - Fix garbage collection logging of device codes and device request (dexidp#1918, @nabokihms) - Discovery endpoint contains updated claims and auth methods (dexidp#1951, @nabokihms) - Return invalid_grant error if auth code is invalid or expired (dexidp#1952, @nabokihms) - Return an error to auth requests with the "request" parameter (dexidp#1956, @nabokihms) **Minor changes:** - Change default themes to light/dark (dexidp#1858, @nabokihms) - Various developer experience improvements - Dependency upgrades - Tons of small fixes and changes
Signed-off-by: m.nabokikh maksim.nabokikh@flant.com
Overview
Add graceful shutdown mechanism to all servers:
What this PR does / why we need it
Closes #1942
Does this PR introduce a user-facing change?