From 6b01b7a3f0bfeb2a061e9ccc5c8e01405d3347f2 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 17 Sep 2024 20:24:21 +0200 Subject: [PATCH] Catch SIGHUP as early as possible to avoid process termination Fixes https://github.com/prometheus/prometheus/issues/14917 Signed-off-by: Julius Volz --- cmd/prometheus/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 24e666cb6..fc51e0649 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -260,6 +260,11 @@ func (c *flagConfig) setFeatureListOptions(logger log.Logger) error { } func main() { + // Catch HUP (reload) signals as early as possible, so that an early HUP + // does not terminate the process. + hup := make(chan os.Signal, 1) + signal.Notify(hup, syscall.SIGHUP) + if os.Getenv("DEBUG") != "" { runtime.SetBlockProfileRate(20) runtime.SetMutexProfileFraction(20) @@ -1067,11 +1072,6 @@ func main() { } { // Reload handler. - - // Make sure that sighup handler is registered with a redirect to the channel before the potentially - // long and synchronous tsdb init. - hup := make(chan os.Signal, 1) - signal.Notify(hup, syscall.SIGHUP) cancel := make(chan struct{}) var checksum string