From 77c04202a28acaba1d97779fecbe53ace065e2bb Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 10 May 2019 22:27:11 -0400 Subject: [PATCH] server: run cleanupFunc before Exit (#4324) Ensure gaiad shutdown Tendermint gracefully upon receiving SIGINT and SIGTERM. Closes: #4323 --- server/util.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/server/util.go b/server/util.go index 6fe6cce516..6fc4e5323c 100644 --- a/server/util.go +++ b/server/util.go @@ -216,14 +216,17 @@ func TrapSignal(cleanupFunc func()) { signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { sig := <-sigs - switch sig { - case syscall.SIGTERM: - defer cleanupFunc() - os.Exit(128 + int(syscall.SIGTERM)) - case syscall.SIGINT: - defer cleanupFunc() - os.Exit(128 + int(syscall.SIGINT)) + if cleanupFunc != nil { + cleanupFunc() } + exitCode := 128 + switch sig { + case syscall.SIGINT: + exitCode += int(syscall.SIGINT) + case syscall.SIGTERM: + exitCode += int(syscall.SIGTERM) + } + os.Exit(exitCode) }() }