fix cache_query race condition

This commit is contained in:
Jack Robison 2020-01-26 12:26:46 -05:00
parent 65d9dca917
commit a10ae70773
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -919,12 +919,9 @@ class LBRYElectrumX(SessionBase):
metrics.start()
cache = self.session_mgr.search_cache[query_name]
cache_key = str(kwargs)
cache_item = cache.get(cache_key)
if cache_item is None:
cache_item = cache[cache_key] = ResultCacheItem()
elif cache_item.result is not None:
metrics.cache_response()
return cache_item.result
if cache_key not in cache:
cache[cache_key] = ResultCacheItem()
cache_item = cache[cache_key]
async with cache_item.lock:
if cache_item.result is None:
cache_item.result = await self.run_in_executor(