Drain collector channel when returning prematurely.

This commit is contained in:
Julius Volz 2014-12-19 13:54:04 +01:00
parent deef44ca73
commit 7fcb2c594a
1 changed files with 7 additions and 1 deletions

View File

@ -33,8 +33,8 @@ import (
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"compress/gzip"
"code.google.com/p/goprotobuf/proto" "code.google.com/p/goprotobuf/proto"
"compress/gzip"
"github.com/prometheus/client_golang/_vendor/goautoneg" "github.com/prometheus/client_golang/_vendor/goautoneg"
"github.com/prometheus/client_golang/model" "github.com/prometheus/client_golang/model"
@ -424,6 +424,12 @@ func (r *registry) writePB(w io.Writer, writeEncoded encoder) (int, error) {
} }
r.mtx.RUnlock() r.mtx.RUnlock()
// Drain metricChan in case of premature return.
defer func() {
for range metricChan {
}
}()
// Gather. // Gather.
for metric := range metricChan { for metric := range metricChan {
// This could be done concurrently, too, but it required locking // This could be done concurrently, too, but it required locking