From 7fcb2c594a974a01493e7923d094ee0ee21c5fbf Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 19 Dec 2014 13:54:04 +0100 Subject: [PATCH] Drain collector channel when returning prematurely. --- prometheus/registry.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prometheus/registry.go b/prometheus/registry.go index cb108f5..65ea520 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -33,8 +33,8 @@ import ( dto "github.com/prometheus/client_model/go" - "compress/gzip" "code.google.com/p/goprotobuf/proto" + "compress/gzip" "github.com/prometheus/client_golang/_vendor/goautoneg" "github.com/prometheus/client_golang/model" @@ -424,6 +424,12 @@ func (r *registry) writePB(w io.Writer, writeEncoded encoder) (int, error) { } r.mtx.RUnlock() + // Drain metricChan in case of premature return. + defer func() { + for range metricChan { + } + }() + // Gather. for metric := range metricChan { // This could be done concurrently, too, but it required locking