From 403dd7367a3b52e8679f6af20c1a91d7b9059bc8 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 2 Dec 2021 22:41:57 +0800 Subject: [PATCH] fix #1288 (#1292) * fix #1288 * chore: make wrapup & shutdown callbacks run simulatenously --- core/proc/shutdown.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/proc/shutdown.go b/core/proc/shutdown.go index a73c6fa5..27285c64 100644 --- a/core/proc/shutdown.go +++ b/core/proc/shutdown.go @@ -11,6 +11,7 @@ import ( "time" "github.com/tal-tech/go-zero/core/logx" + "github.com/tal-tech/go-zero/core/threading" ) const ( @@ -46,10 +47,10 @@ func gracefulStop(signals chan os.Signal) { signal.Stop(signals) logx.Info("Got signal SIGTERM, shutting down...") - wrapUpListeners.notifyListeners() + go wrapUpListeners.notifyListeners() time.Sleep(wrapUpTime) - shutdownListeners.notifyListeners() + go shutdownListeners.notifyListeners() time.Sleep(delayTimeBeforeForceQuit - wrapUpTime) logx.Infof("Still alive after %v, going to force kill the process...", delayTimeBeforeForceQuit) @@ -81,7 +82,9 @@ func (lm *listenerManager) notifyListeners() { lm.lock.Lock() defer lm.lock.Unlock() + group := threading.NewRoutineGroup() for _, listener := range lm.listeners { - listener() + group.RunSafe(listener) } + group.Wait() }