Skip to content

Commit

Permalink
fix: prevent multiple channel close in Telemetry Stop method (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard authored Dec 1, 2024
1 parent 9a1ec23 commit e73926d
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 e73926d

Please sign in to comment.