From 306a0066d144e4a2f32e071684173d07f86dfb75 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 7 Jun 2021 21:59:43 -0700 Subject: [PATCH] Fix concurrency crash. Closes #1067 --- core/data/cache.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/data/cache.go b/core/data/cache.go index 784999814..2af34ab42 100644 --- a/core/data/cache.go +++ b/core/data/cache.go @@ -1,9 +1,17 @@ package data -import "errors" +import ( + "errors" + "sync" +) + +var _cacheLock = sync.Mutex{} // GetCachedValue will return a value for key from the cache. func (ds *Datastore) GetCachedValue(key string) ([]byte, error) { + _cacheLock.Lock() + defer _cacheLock.Unlock() + // Check for a cached value if val, ok := ds.cache[key]; ok { return val, nil @@ -14,5 +22,8 @@ func (ds *Datastore) GetCachedValue(key string) ([]byte, error) { // SetCachedValue will set a value for key in the cache. func (ds *Datastore) SetCachedValue(key string, b []byte) { + _cacheLock.Lock() + defer _cacheLock.Unlock() + ds.cache[key] = b }