Merge pull request #40 from prometheus/drain-collect-channel

Drain collector channel when returning prematurely.
This commit is contained in:
juliusv 2014-12-19 14:22:52 +01:00
commit 2657498a2f
3 changed files with 11 additions and 4 deletions

View File

@ -1,7 +1,7 @@
language: go language: go
go: go:
- 1.2.1 - 1.4
script: script:
- make -f Makefile - make -f Makefile

View File

@ -18,7 +18,7 @@ MAC_OS_X_VERSION ?= 10.8
BUILD_PATH = $(PWD)/.build BUILD_PATH = $(PWD)/.build
export GO_VERSION = 1.2.1 export GO_VERSION = 1.4
export GOOS = $(subst Darwin,darwin,$(subst Linux,linux,$(OS))) export GOOS = $(subst Darwin,darwin,$(subst Linux,linux,$(OS)))
ifeq ($(GOOS),darwin) ifeq ($(GOOS),darwin)
@ -29,6 +29,7 @@ endif
export GOARCH = $(subst x86_64,amd64,$(ARCH)) export GOARCH = $(subst x86_64,amd64,$(ARCH))
export GOPKG = go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz export GOPKG = go$(GO_VERSION).$(GOOS)-$(GOARCH)$(RELEASE_SUFFIX).tar.gz
export GOURL = http://golang.org/dl
export GOROOT = $(BUILD_PATH)/root/go export GOROOT = $(BUILD_PATH)/root/go
export GOPATH = $(BUILD_PATH)/root/gopath export GOPATH = $(BUILD_PATH)/root/gopath
export GOCC = $(GOROOT)/bin/go export GOCC = $(GOROOT)/bin/go
@ -57,7 +58,7 @@ $(BUILD_PATH)/root: $(BUILD_PATH)
mkdir -vp $(BUILD_PATH)/root mkdir -vp $(BUILD_PATH)/root
$(BUILD_PATH)/cache/$(GOPKG): $(BUILD_PATH)/cache $(BUILD_PATH)/cache/$(GOPKG): $(BUILD_PATH)/cache
curl -o $@ http://go.googlecode.com/files/$(GOPKG) curl -o $@ -L $(GOURL)/$(GOPKG)
$(GOCC): $(BUILD_PATH)/root $(BUILD_PATH)/cache/$(GOPKG) $(GOCC): $(BUILD_PATH)/root $(BUILD_PATH)/cache/$(GOPKG)
tar -C $(BUILD_PATH)/root -xzf $(BUILD_PATH)/cache/$(GOPKG) tar -C $(BUILD_PATH)/root -xzf $(BUILD_PATH)/cache/$(GOPKG)

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