From 66b0aa3b4505d01f82cf4d0e71083112793723eb Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Sun, 28 Jan 2018 22:24:31 +0530 Subject: [PATCH] Fixed race condition in map iteration and map write in Discovery (#3735) (#3738) * Fixed concurrent map iteration and map write in Discovery (#3735) * discovery: Changed Lock to RLock in Collect --- discovery/file/file.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discovery/file/file.go b/discovery/file/file.go index 5e10c1a54..eaba2df6f 100644 --- a/discovery/file/file.go +++ b/discovery/file/file.go @@ -96,9 +96,11 @@ func (t *TimestampCollector) Collect(ch chan<- prometheus.Metric) { uniqueFiles := make(map[string]float64) t.lock.RLock() for fileSD := range t.discoverers { + fileSD.lock.RLock() for filename, timestamp := range fileSD.timestamps { uniqueFiles[filename] = timestamp } + fileSD.lock.RUnlock() } t.lock.RUnlock() for filename, timestamp := range uniqueFiles {