Skip to content

Commit

Permalink
fix: prevent multiple channel close in Telemetry Stop method
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Dec 1, 2024
1 parent 9a1ec23 commit 330d02e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion telemetry/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 330d02e

Please sign in to comment.