Skip to content

Commit

Permalink
Fix bug in graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
cl9200 committed Oct 6, 2019
1 parent 83d30bf commit f6280e7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,17 @@ func TrapSignal(cleanupFunc func()) {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
if cleanupFunc != nil {
cleanupFunc()
}
exitCode := 128
switch sig {
case syscall.SIGTERM:
defer cleanupFunc()
os.Exit(128 + int(syscall.SIGTERM))
case syscall.SIGINT:
defer cleanupFunc()
os.Exit(128 + int(syscall.SIGINT))
exitCode += int(syscall.SIGINT)
case syscall.SIGTERM:
exitCode += int(syscall.SIGINT)
}
os.Exit(exitCode)
}()
}

Expand Down

0 comments on commit f6280e7

Please sign in to comment.