From cc304fd6e2146615285a90f08418dba43cea49b4 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 15 Oct 2024 15:37:29 +0545 Subject: [PATCH] fix: run shutdown once --- shutdown/shutdown.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shutdown/shutdown.go b/shutdown/shutdown.go index 7fe7ab04..d2bd3ca7 100644 --- a/shutdown/shutdown.go +++ b/shutdown/shutdown.go @@ -3,13 +3,14 @@ package shutdown import ( "os" "os/signal" + "sync" "github.com/flanksource/commons/logger" ) var shutdownHooks []func() -func Shutdown() { +var Shutdown = sync.OnceFunc(func() { if len(shutdownHooks) == 0 { return } @@ -18,7 +19,7 @@ func Shutdown() { fn() } shutdownHooks = []func(){} -} +}) func ShutdownAndExit(code int, msg string) { Shutdown()