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
This commit is contained in:
Ganesh Vernekar 2018-01-28 22:24:31 +05:30 committed by Goutham Veeramachaneni
parent 8b20cb1e8d
commit 66b0aa3b45
1 changed files with 2 additions and 0 deletions

View File

@ -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 {