From 64b5966b48cfec22770bbc0daaf4fff08eb4c2ab Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 13 Jan 2024 04:41:46 +0400 Subject: [PATCH] Cause a proper server shutdown if a list reload fail by defering it. --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 58c4f2d..c8ee25a 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,12 @@ func main() { log.Fatalf("ListenAndServe: %s\n", err) } }() + defer func() { + srv.SetKeepAlivesEnabled(false) + if err := srv.Shutdown(context.Background()); err != nil { + log.Fatalf("%s\n", err) + } + }() syssignal := make(chan os.Signal, 1) signal.Notify(syssignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) @@ -80,11 +86,7 @@ func main() { case os.Interrupt: fallthrough case syscall.SIGINT | syscall.SIGTERM: - srv.SetKeepAlivesEnabled(false) - if err := srv.Shutdown(context.Background()); err != nil { - log.Fatalf("%s\n", err) - } - os.Exit(0) + return case syscall.SIGHUP: newconf, err := LoadConfiguration(*configPath) if err != nil {