Skip to content

Commit daeaac0

Browse files
authored
Merge pull request #472 from prometheus/beorn7/registry
Fix a few minor things...
2 parents 2d5a649 + ff01778 commit daeaac0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

prometheus/collector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ type Collector interface {
4040
// Collector may yield any Metric it sees fit in its Collect method.
4141
//
4242
// 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.
4445
//
4546
// If a Collector encounters an error while executing this method, it
4647
// must send an invalid descriptor (created with NewInvalidDesc) to

prometheus/registry.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ type Registerer interface {
107107
// Collector, and for providing a Collector that will not cause
108108
// inconsistent metrics on collection. (This would lead to scrape
109109
// errors.)
110-
//
111-
// It is in general not safe to register the same Collector multiple
112-
// times concurrently.
113110
Register(Collector) error
114111
// MustRegister works like Register but registers any number of
115112
// Collectors and panics upon the first registration that causes an
@@ -273,7 +270,12 @@ func (r *Registry) Register(c Collector) error {
273270
close(descChan)
274271
}()
275272
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+
}()
277279
// Conduct various tests...
278280
for desc := range descChan {
279281

0 commit comments

Comments
 (0)