From c12ab6ff5cb4e6d9f78c89a172f8cc08bcdf56d5 Mon Sep 17 00:00:00 2001 From: dnj Date: Tue, 6 Dec 2016 09:29:01 -0800 Subject: [PATCH] impl/memory: Fix memcache stats race. Fix a race in memcache stats that was caused by modification of common stats varibles while holding a possibly-shared RLock. This fix switches locking from RWMutex to Mutex, since potentially every access contains mutations to the shared state. BUG=None TEST=local - Re-ran external test with fix, race no longer triggered. R=iannucci@chromium.org Review-Url: https://codereview.chromium.org/2554793002 --- impl/memory/memcache.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/impl/memory/memcache.go b/impl/memory/memcache.go index 9e2d55c..624617b 100644 --- a/impl/memory/memcache.go +++ b/impl/memory/memcache.go @@ -78,7 +78,7 @@ func (m *mcDataItem) toUserItem(key string) *mcItem { } type memcacheData struct { - lock sync.RWMutex + lock sync.Mutex items map[string]*mcDataItem casID uint64 @@ -258,8 +258,8 @@ func (m *memcacheImpl) GetMulti(keys []string, cb mc.RawItemCB) error { for i, k := range keys { itms[i], errs[i] = func() (mc.Item, error) { - m.data.lock.RLock() - defer m.data.lock.RUnlock() + m.data.lock.Lock() + defer m.data.lock.Unlock() val, err := m.data.retrieveLocked(now, k) if err != nil { return nil, err @@ -345,8 +345,8 @@ func (m *memcacheImpl) Increment(key string, delta int64, initialValue *uint64) } func (m *memcacheImpl) Stats() (*mc.Statistics, error) { - m.data.lock.RLock() - defer m.data.lock.RUnlock() + m.data.lock.Lock() + defer m.data.lock.Unlock() ret := m.data.stats return &ret, nil