File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ type Collector interface {
40
40
// Collector may yield any Metric it sees fit in its Collect method.
41
41
//
42
42
// This method idempotently sends the same descriptors throughout the
43
- // lifetime of the Collector.
43
+ // lifetime of the Collector. It may be called concurrently and
44
+ // therefore must be implemented in a concurrency safe way.
44
45
//
45
46
// If a Collector encounters an error while executing this method, it
46
47
// must send an invalid descriptor (created with NewInvalidDesc) to
Original file line number Diff line number Diff line change @@ -107,9 +107,6 @@ type Registerer interface {
107
107
// Collector, and for providing a Collector that will not cause
108
108
// inconsistent metrics on collection. (This would lead to scrape
109
109
// errors.)
110
- //
111
- // It is in general not safe to register the same Collector multiple
112
- // times concurrently.
113
110
Register (Collector ) error
114
111
// MustRegister works like Register but registers any number of
115
112
// Collectors and panics upon the first registration that causes an
@@ -273,7 +270,12 @@ func (r *Registry) Register(c Collector) error {
273
270
close (descChan )
274
271
}()
275
272
r .mtx .Lock ()
276
- defer r .mtx .Unlock ()
273
+ defer func () {
274
+ // Drain channel in case of premature return to not leak a goroutine.
275
+ for range descChan {
276
+ }
277
+ r .mtx .Unlock ()
278
+ }()
277
279
// Conduct various tests...
278
280
for desc := range descChan {
279
281
You can’t perform that action at this time.
0 commit comments