Drain the desc channel after registering

This avoids leaking goroutines.

Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
beorn7 2018-09-29 10:43:39 +02:00
parent 2d5a6493f8
commit 7eb5e8a08a
1 changed files with 6 additions and 1 deletions

View File

@ -273,7 +273,12 @@ func (r *Registry) Register(c Collector) error {
close(descChan) close(descChan)
}() }()
r.mtx.Lock() 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... // Conduct various tests...
for desc := range descChan { for desc := range descChan {