Skip to content
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

Merged
merged 3 commits into from
Feb 5, 2021
Merged

Conversation

nabokihms
Copy link
Member

Signed-off-by: m.nabokikh maksim.nabokikh@flant.com

Overview

Add graceful shutdown mechanism to all servers:

  • HTTP
  • HTTPS
  • Telemetry
  • grpc

What this PR does / why we need it

Closes #1942

Does this PR introduce a user-facing change?

Graceful shutdown.

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Copy link
Member

@sagikazarmark sagikazarmark left a 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 {
Copy link
Member

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.

Copy link
Member Author

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
Comment on lines 85 to 87
if err := l.Close(); err != nil {
logger.Errorf("gracefully close (%s) listener: %v", name, err)
}
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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 Show resolved Hide resolved
cmd/dex/serve.go Outdated
Comment on lines 379 to 381
if err := grpcListener.Close(); err != nil {
logger.Errorf("failed to gracefully close (grpc) listener: %v", err)
}
Copy link
Member

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}
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Member Author

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>
Copy link
Member

@sagikazarmark sagikazarmark left a 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!

cmd/dex/serve.go Outdated Show resolved Hide resolved
cmd/dex/serve.go Outdated Show resolved Hide resolved
cmd/dex/serve.go Outdated Show resolved Hide resolved
Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nabokihms !

@sagikazarmark sagikazarmark added this to the v2.28.0 milestone Feb 5, 2021
@sagikazarmark sagikazarmark merged commit e50d9a9 into dexidp:master Feb 5, 2021
xtremerui pushed a commit to concourse/dex that referenced this pull request Mar 16, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graceful shutdown
2 participants