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

fix: don't use a finished context for graceful shutdown #20355

Merged
merged 5 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
1. [20349](https://github.com/influxdata/influxdb/pull/20349): Ensure `influxdb` service sees default env variables when running under `init.d`.
1. [20317](https://github.com/influxdata/influxdb/pull/20317): Don't ignore failures to set password during initial user onboarding.
1. [20362](https://github.com/influxdata/influxdb/pull/20362): Don't overwrite stack name/description on `influx stack update`.
1. [20355](https://github.com/influxdata/influxdb/pull/20355): Fix timeout setup for `influxd` graceful shutdown.

## v2.0.3 [2020-12-14]

Expand Down
17 changes: 9 additions & 8 deletions cmd/influxd/launcher/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ func cmdRunE(ctx context.Context, o *InfluxdOpts) func() error {
return func() error {
fluxinit.FluxInit()

// exit with SIGINT and SIGTERM
ctx = signals.WithStandardSignals(ctx)

l := NewLauncher()
if err := l.run(ctx, o); err != nil {

// Start the launcher and wait for it to exit on SIGINT or SIGTERM.
runCtx := signals.WithStandardSignals(ctx)
Copy link
Contributor

@ayang64 ayang64 Feb 9, 2021

Choose a reason for hiding this comment

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

why assign this to runCtx and not simply:

ctx = signals.WithStandardSignals(ctx)

also, if you're using go 1.15, i think you can use os/signal.NotifyContext().
?

if err := l.run(runCtx, o); err != nil {
return err
}
<-ctx.Done()
<-runCtx.Done()

// Attempt clean shutdown.
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
danxmoran marked this conversation as resolved.
Show resolved Hide resolved
// Tear down the launcher, allowing it a few seconds to finish any
// in-progress requests.
shutdownCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
l.Shutdown(ctx)
l.Shutdown(shutdownCtx)

return nil
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (m *Launcher) Engine() Engine {

// Shutdown shuts down the HTTP server and waits for all services to clean up.
func (m *Launcher) Shutdown(ctx context.Context) {
m.httpServer.Shutdown(ctx)
if err := m.httpServer.Shutdown(ctx); err != nil {
m.log.Error("Failed to close HTTP server", zap.Error(err))
}

m.log.Info("Stopping", zap.String("service", "task"))

Expand Down