# HG changeset patch # User Martin Bornhold # Date 2016-07-14 07:07:19 # Node ID cbe557819f37e37515c0ba4c9201f895224edf2d # Parent af6adc7d1ca920ed8aab350b4cb9c9bcac6f0c31 vcs: Use a thread scoped cache invalidation context to cache repository objects. Without this change the cache is on a process scope. If running with multiple threads this leads to sharing the cached object between threads. This will cause exceptions if multiple threads are trying to access the same curl object. Even worse it allows multiple threads to operate on the same repository object concurrently. diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1977,7 +1977,7 @@ class Repository(Base, BaseModel): return self._get_instance() invalidator_context = CacheKey.repo_context_cache( - _get_repo, self.repo_name, None) + _get_repo, self.repo_name, None, thread_scoped=True) with invalidator_context as context: context.invalidate() @@ -2848,7 +2848,8 @@ class CacheKey(Base, BaseModel): return None @classmethod - def repo_context_cache(cls, compute_func, repo_name, cache_type): + def repo_context_cache(cls, compute_func, repo_name, cache_type, + thread_scoped=False): """ @cache_region('long_term') def _heavy_calculation(cache_key): @@ -2864,7 +2865,8 @@ class CacheKey(Base, BaseModel): assert computed == 'result' """ from rhodecode.lib import caches - return caches.InvalidationContext(compute_func, repo_name, cache_type) + return caches.InvalidationContext( + compute_func, repo_name, cache_type, thread_scoped=thread_scoped) class ChangesetComment(Base, BaseModel):