From 5ff45a7ee7a99503e2d406739412da6334b939cf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 May 2021 07:26:02 +0530 Subject: [PATCH] Hold the VLs cache lock when checking if the cache exists --- src/calibre/db/cache.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 9792574338..1c0f9c1b69 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -2231,13 +2231,13 @@ class Cache(object): @read_api def virtual_libraries_for_books(self, book_ids, virtual_fields=None): - if self.vls_for_books_cache is None: - # Using a list is slightly faster than a set. - c = defaultdict(list) - # use a primitive lock to ensure that only one thread is updating - # the cache and that recursive calls don't do the update. This - # method can recurse via self._search() - with try_lock(self.vls_cache_lock) as got_lock: + # use a primitive lock to ensure that only one thread is updating + # the cache and that recursive calls don't do the update. This + # method can recurse via self._search() + with try_lock(self.vls_cache_lock) as got_lock: + if self.vls_for_books_cache is None: + # Using a list is slightly faster than a set. + c = defaultdict(list) if not got_lock: # We get here if resolving the books in a VL triggers another VL # calculation. This can be 'real' recursion, in which case the