From 330d02e5822a9d789a816f7307dbf807feff9c77 Mon Sep 17 00:00:00 2001 From: dmachard <5562930+dmachard@users.noreply.github.com> Date: Sun, 1 Dec 2024 18:48:55 +0100 Subject: [PATCH] fix: prevent multiple channel close in Telemetry Stop method --- telemetry/prometheus.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telemetry/prometheus.go b/telemetry/prometheus.go index bce272cb..46deed2e 100644 --- a/telemetry/prometheus.go +++ b/telemetry/prometheus.go @@ -44,6 +44,7 @@ type PrometheusCollector struct { Record chan WorkerStats data map[string]WorkerStats // To store the worker stats stop chan struct{} // Channel to signal stopping + stopOnce sync.Once promPrefix string } @@ -154,7 +155,10 @@ func (t *PrometheusCollector) Describe(ch chan<- *prometheus.Desc) { } func (t *PrometheusCollector) Stop() { - close(t.stop) // Signal the stop channel to stop the goroutine + // only close one even if called several time + t.stopOnce.Do(func() { + close(t.stop) // Signal the stop channel to stop the goroutine + }) } func InitTelemetryServer(config *pkgconfig.Config, logger *logger.Logger) (*http.Server, *PrometheusCollector, chan error) {