diff --git a/prometheus/registry.go b/prometheus/registry.go index 2c0b908..8d274e0 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -273,7 +273,12 @@ func (r *Registry) Register(c Collector) error { close(descChan) }() r.mtx.Lock() - defer r.mtx.Unlock() + defer func() { + // Drain channel in case of premature return to not leak a goroutine. + for range descChan { + } + r.mtx.Unlock() + }() // Conduct various tests... for desc := range descChan {