From 83fcadf2e3357594e880b9f53b034cf24dd2a31d Mon Sep 17 00:00:00 2001 From: muXxer <mux3r@web.de> Date: Tue, 17 Sep 2019 21:18:02 +0200 Subject: [PATCH] Fixes deadlocks in LRU cache --- packages/datastructure/lru_cache.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/datastructure/lru_cache.go b/packages/datastructure/lru_cache.go index f70a86ae..3956eb1e 100644 --- a/packages/datastructure/lru_cache.go +++ b/packages/datastructure/lru_cache.go @@ -168,9 +168,9 @@ func (cache *LRUCache) Contains(key interface{}) (result bool) { keyMutex.RLock() cache.mutex.RLock() if element, exists := cache.directory[key]; exists { + cache.mutex.RUnlock() keyMutex.RUnlock() - cache.mutex.RUnlock() cache.mutex.Lock() cache.promoteElement(element) cache.mutex.Unlock() @@ -201,11 +201,11 @@ func (cache *LRUCache) Get(key interface{}) (result interface{}) { result = element.GetValue().(*lruCacheElement).value - keyMutex.RUnlock() } else { cache.mutex.RUnlock() } + keyMutex.RUnlock() cache.krwMutex.Free(key) return @@ -243,6 +243,7 @@ func (cache *LRUCache) Delete(key interface{}) bool { delete(cache.directory, key) cache.size-- + keyMutex.Unlock() if cache.options.EvictionCallback != nil { cache.options.EvictionCallback(key, entry.GetValue().(*lruCacheElement).key) -- GitLab