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/graceful shutdown #1007

Merged
merged 10 commits into from
Feb 23, 2021
14 changes: 6 additions & 8 deletions config/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
* The signals are different on different platforms.
* We define them by using 'package build' feature https://golang.org/pkg/go/build/
*/
const defaultShutDownTime = time.Second * 60

// nolint
func GracefulShutdownInit() {
Expand All @@ -64,20 +65,17 @@ func GracefulShutdownInit() {
case sig := <-signals:
logger.Infof("get signal %s, application will shutdown.", sig)
// gracefulShutdownOnce.Do(func() {
time.AfterFunc(totalTimeout(), func() {
logger.Warn("Shutdown gracefully timeout, application will shutdown immediately. ")
os.Exit(0)
})
BeforeShutdown()

// those signals' original behavior is exit with dump ths stack, so we try to keep the behavior
for _, dumpSignal := range DumpHeapShutdownSignals {
if sig == dumpSignal {
debug.WriteHeapDump(os.Stdout.Fd())
}
}

time.AfterFunc(totalTimeout(), func() {
logger.Warn("Shutdown gracefully timeout, application will shutdown immediately. ")
os.Exit(0)
})

os.Exit(0)
}
}()
Expand Down Expand Up @@ -196,7 +194,7 @@ func waitingProcessedTimeout(shutdownConfig *ShutdownConfig) {
}

func totalTimeout() time.Duration {
var providerShutdown time.Duration
var providerShutdown = defaultShutDownTime
if providerConfig != nil && providerConfig.ShutdownConfig != nil {
providerShutdown = providerConfig.ShutdownConfig.GetTimeout()
}
Expand Down