Skip to content

Commit 7eb5e8a

Browse files
author
beorn7
committed
Drain the desc channel after registering
This avoids leaking goroutines. Signed-off-by: beorn7 <[email protected]>
1 parent 2d5a649 commit 7eb5e8a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

prometheus/registry.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,12 @@ func (r *Registry) Register(c Collector) error {
273273
close(descChan)
274274
}()
275275
r.mtx.Lock()
276-
defer r.mtx.Unlock()
276+
defer func() {
277+
// Drain channel in case of premature return to not leak a goroutine.
278+
for range descChan {
279+
}
280+
r.mtx.Unlock()
281+
}()
277282
// Conduct various tests...
278283
for desc := range descChan {
279284

0 commit comments

Comments
 (0)