From 401315f33750c7fa0374c00bcba8f26f8b67fe7b Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:18:40 +0500 Subject: [PATCH] master fix interruption through ctrl+c (#3834) --- weed/command/master.go | 2 +- weed/util/grace/signal_handling.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/weed/command/master.go b/weed/command/master.go index a74389b1f..39dbf42ed 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -255,7 +255,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) { } grace.OnInterrupt(ms.Shutdown) - grace.OnInterrupt(grpcS.GracefulStop) + grace.OnInterrupt(grpcS.Stop) grace.OnReload(func() { if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader { ms.Topo.HashicorpRaft.LeadershipTransfer() diff --git a/weed/util/grace/signal_handling.go b/weed/util/grace/signal_handling.go index 14b998796..0fc0f43e1 100644 --- a/weed/util/grace/signal_handling.go +++ b/weed/util/grace/signal_handling.go @@ -4,8 +4,11 @@ package grace import ( + "github.com/seaweedfs/seaweedfs/weed/glog" "os" "os/signal" + "reflect" + "runtime" "sync" "syscall" ) @@ -16,6 +19,10 @@ var interruptHookLock sync.RWMutex var reloadHooks = make([]func(), 0) var reloadHookLock sync.RWMutex +func GetFunctionName(i interface{}) string { + return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() +} + func init() { signalChan = make(chan os.Signal, 1) signal.Notify(signalChan, @@ -38,6 +45,7 @@ func init() { } else { interruptHookLock.RLock() for _, hook := range interruptHooks { + glog.V(4).Infof("exec interrupt hook func name:%s", GetFunctionName(hook)) hook() } interruptHookLock.RUnlock()