Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: client/named_cache.py

Issue 2752293002: named_caches: make more resilient to corrupted state (Closed)
Patch Set: lint Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/tests/named_cache_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/named_cache.py
diff --git a/client/named_cache.py b/client/named_cache.py
index 50a4e1c04fb9005f5d4a83150f3ee405f0044e63..7566ccca9a5da9917e19e44584be641031861bdb 100644
--- a/client/named_cache.py
+++ b/client/named_cache.py
@@ -63,12 +63,17 @@ class CacheManager(object):
Returns a context manager that must be closed as soon as possible.
"""
- state_path = os.path.join(self.root_dir, u'state.json')
with self._lock:
+ state_path = os.path.join(self.root_dir, u'state.json')
+ assert self._lru is None, 'acquired lock, but self._lru is not None'
if os.path.isfile(state_path):
- self._lru = lru.LRUDict.load(state_path)
- else:
- self._lru = lru.LRUDict()
+ try:
+ self._lru = lru.LRUDict.load(state_path)
+ except ValueError:
+ logging.exception('failed to load named cache state file')
+ logging.warning('deleting named caches')
+ file_path.rmtree(self.root_dir)
+ self._lru = self._lru or lru.LRUDict()
if time_fn:
self._lru.time_fn = time_fn
try:
« no previous file with comments | « no previous file | client/tests/named_cache_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698