Merge pull request #62 from prometheus/fix-writepb-race

Fix race condition in writePB().
This commit is contained in:
Björn Rabenstein 2015-01-31 23:52:10 +01:00
commit aa1328d02c
1 changed files with 3 additions and 2 deletions

View File

@ -400,7 +400,6 @@ func (r *registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
func (r *registry) writePB(w io.Writer, writeEncoded encoder) (int, error) {
metricFamiliesByName := make(map[string]*dto.MetricFamily, len(r.dimHashesByName))
var metricHashes map[uint64]struct{}
if r.collectChecksEnabled {
metricHashes = make(map[uint64]struct{})
@ -408,9 +407,11 @@ func (r *registry) writePB(w io.Writer, writeEncoded encoder) (int, error) {
metricChan := make(chan Metric, capMetricChan)
wg := sync.WaitGroup{}
r.mtx.RLock()
metricFamiliesByName := make(map[string]*dto.MetricFamily, len(r.dimHashesByName))
// Scatter.
// (Collectors could be complex and slow, so we call them all at once.)
r.mtx.RLock()
wg.Add(len(r.collectorsByID))
go func() {
wg.Wait()