From 83c9035971e4b594686391a7ff052a7d1fe13771 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 19 Feb 2022 16:36:25 +0000 Subject: [PATCH] Immediately Hammer if second kill is sent (#18823) Currently Gitea will wait for HammerTime or nice shutdown if kill -1 or kill -2 is sent. We should just immediately hammer if there is a second kill. Signed-off-by: Andrew Thornton --- modules/graceful/manager.go | 1 + modules/graceful/manager_unix.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/graceful/manager.go b/modules/graceful/manager.go index 031c10d41ba4..f78357360746 100644 --- a/modules/graceful/manager.go +++ b/modules/graceful/manager.go @@ -193,6 +193,7 @@ func (g *Manager) RunAtHammer(hammer func()) { func (g *Manager) doShutdown() { if !g.setStateTransition(stateRunning, stateShuttingDown) { + g.DoImmediateHammer() return } g.lock.Lock() diff --git a/modules/graceful/manager_unix.go b/modules/graceful/manager_unix.go index fcbb16a3bb96..99e84d73e834 100644 --- a/modules/graceful/manager_unix.go +++ b/modules/graceful/manager_unix.go @@ -168,8 +168,12 @@ func (g *Manager) DoGracefulRestart() { if setting.GracefulRestartable { log.Info("PID: %d. Forking...", os.Getpid()) err := g.doFork() - if err != nil && err.Error() != "another process already forked. Ignoring this one" { - log.Error("Error whilst forking from PID: %d : %v", os.Getpid(), err) + if err != nil { + if err.Error() == "another process already forked. Ignoring this one" { + g.DoImmediateHammer() + } else { + log.Error("Error whilst forking from PID: %d : %v", os.Getpid(), err) + } } } else { log.Info("PID: %d. Not set restartable. Shutting down...", os.Getpid())