From 6bdde0d6d41818cf93aea499e8a55e28e85eb641 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 10 Nov 2019 22:03:46 +0200 Subject: [PATCH] lib/storage: eliminate data race when updating lastSyncTime in dateMetricIDCache.Has --- lib/storage/storage.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index ef57fef82..0441ebe40 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1020,7 +1020,7 @@ type dateMetricIDCache struct { // Contains mutable map protected by mu byDateMutable *byDateMetricIDMap lastSyncTime time.Time - mu sync.RWMutex + mu sync.Mutex } func newDateMetricIDCache() *dateMetricIDCache { @@ -1057,7 +1057,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool { // Slow path. Check mutable map. currentTime := time.Now() - dmc.mu.RLock() + dmc.mu.Lock() v = dmc.byDateMutable.get(date) ok := v.Has(metricID) mustSync := false @@ -1065,7 +1065,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool { mustSync = true dmc.lastSyncTime = currentTime } - dmc.mu.RUnlock() + dmc.mu.Unlock() if mustSync { dmc.sync()