Skip to content

Commit 06cb0b9

Browse files
committed
Fix goroutines leaks
1 parent 67f2b9b commit 06cb0b9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

internal/collector/collector.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func (n PgscvCollector) Collect(out chan<- prometheus.Metric) {
205205
err := n.Config.FillPostgresServiceConfig(n.Config.ConnTimeout)
206206
if err != nil {
207207
log.Errorf("update service config failed: %s", err.Error())
208+
return
208209
}
209210
}
210211
if n.Config.ConcurrencyLimit != nil {
@@ -240,9 +241,14 @@ func (n PgscvCollector) Collect(out chan<- prometheus.Metric) {
240241
wgCollector.Add(len(n.Collectors))
241242
for name, c := range n.Collectors {
242243
go func(name string, c Collector) {
243-
sem <- struct{}{}
244+
if concurrencyLimit > 0 {
245+
sem <- struct{}{}
246+
}
244247
defer func() {
245-
<-sem
248+
if concurrencyLimit > 0 {
249+
<-sem
250+
}
251+
246252
wgCollector.Done()
247253
}()
248254
collect(name, n.Config, c, pipelineIn)

0 commit comments

Comments
 (0)