From 111b03f6451bb84de37585bdb8872b725029c1f1 Mon Sep 17 00:00:00 2001 From: Denis Machard <5562930+dmachard@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:06:49 +0200 Subject: [PATCH] stop collect before monitor on worker (#850) --- dnscollector.go | 19 ++++++++++--------- workers/worker.go | 7 ++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dnscollector.go b/dnscollector.go index 40691467..b6e28f92 100644 --- a/dnscollector.go +++ b/dnscollector.go @@ -219,6 +219,15 @@ func main() { case <-sigTerm: logger.Warning("main - exiting...") + // and stop all workers + for _, c := range mapCollectors { + c.Stop() + } + + for _, l := range mapLoggers { + l.Stop() + } + // gracefully shutdown the HTTP server if config.Global.Telemetry.Enabled { logger.Info("main - telemetry is stopping") @@ -228,15 +237,7 @@ func main() { logger.Error("main - telemetry error shutting down http server - %s", err.Error()) } - } - - // and stop all workers - for _, c := range mapCollectors { - c.Stop() - } - - for _, l := range mapLoggers { - l.Stop() + logger.Info("main - telemetry stopped") } // unblock main function diff --git a/workers/worker.go b/workers/worker.go index b56a5754..ca84f9ec 100644 --- a/workers/worker.go +++ b/workers/worker.go @@ -173,13 +173,14 @@ func (w *GenericWorker) LoggingDone() { } func (w *GenericWorker) Stop() { - w.LogInfo("stopping monitor...") - w.stopMonitor <- true - <-w.doneMonitor w.LogInfo("stopping collect...") w.stopRun <- true <-w.doneRun + w.LogInfo("stopping monitor...") + w.stopMonitor <- true + <-w.doneMonitor + } func (w *GenericWorker) Monitor() {