From 3ae086fff2f5abf8f309be88ec76d7e74a8e8740 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Thu, 12 Jan 2023 11:59:30 +0100 Subject: [PATCH] Revert "Fixup: make signal handlers a bit simpler." --- cmd/alertmanager/main.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index 18aec9ef..a1bb96d4 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -554,19 +554,31 @@ func run() int { }() var ( - hup = make(chan os.Signal, 1) - term = make(chan os.Signal, 1) + hup = make(chan os.Signal, 1) + hupReady = make(chan bool) + term = make(chan os.Signal, 1) ) signal.Notify(hup, syscall.SIGHUP) signal.Notify(term, os.Interrupt, syscall.SIGTERM) + go func() { + <-hupReady + for { + select { + case <-hup: + // ignore error, already logged in `reload()` + _ = configCoordinator.Reload() + case errc := <-webReload: + errc <- configCoordinator.Reload() + } + } + }() + + // Wait for reload or termination signals. + close(hupReady) // Unblock SIGHUP handler. + for { select { - case <-hup: - // ignore error, already logged in `reload()` - _ = configCoordinator.Reload() - case errc := <-webReload: - errc <- configCoordinator.Reload() case <-term: level.Info(logger).Log("msg", "Received SIGTERM, exiting gracefully...") return 0