From 7dd34c6b4c0ddd9f63d57f7a97480e93548df39a Mon Sep 17 00:00:00 2001 From: Xavier Nicollet Date: Mon, 17 Oct 2022 21:04:10 +0100 Subject: [PATCH] Fixup: make signal handlers a bit simpler. No need to spawn a goroutine, nor wait for a channel. Let's just put everything in a single select call. Signed-off-by: Xavier Nicollet --- cmd/alertmanager/main.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index d8d3ddfe..e6901fd9 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -547,31 +547,19 @@ func run() int { }() var ( - hup = make(chan os.Signal, 1) - hupReady = make(chan bool) - term = make(chan os.Signal, 1) + hup = make(chan os.Signal, 1) + 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