Skip to content

Commit

Permalink
server: run cleanupFunc before Exit (cosmos#4324)
Browse files Browse the repository at this point in the history
Ensure gaiad shutdown Tendermint gracefully upon
receiving SIGINT and SIGTERM.

Closes: cosmos#4323
  • Loading branch information
ebuchman authored and Alessio Treglia committed May 11, 2019
1 parent 829ce17 commit 77c0420
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 @@ -216,14 +216,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.SIGTERM)
}
os.Exit(exitCode)
}()
}

Expand Down

0 comments on commit 77c0420

Please sign in to comment.