revlog: hold a private reference to self._cache stable
authorMatt Mackall <mpm@selenic.com>
Fri, 13 Jun 2014 14:17:14 -0500
branchstable
changeset 21750 4ab287c2d337
parent 21749 f13728d59c0e
child 21751 c5699c2d690b
child 21752 e250a482478e
revlog: hold a private reference to self._cache This keeps other threads from modifying self._cache out from under us. With this and the previous fix, 'hg serve' survives 100k hits with siege.
mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Jun 13 14:16:03 2014 -0500
+++ b/mercurial/revlog.py	Fri Jun 13 14:17:14 2014 -0500
@@ -972,13 +972,14 @@
             node = nodeorrev
             rev = None
 
+        _cache = self._cache # grab local copy of cache to avoid thread race
         cachedrev = None
         if node == nullid:
             return ""
-        if self._cache:
-            if self._cache[0] == node:
-                return self._cache[2]
-            cachedrev = self._cache[1]
+        if _cache:
+            if _cache[0] == node:
+                return _cache[2]
+            cachedrev = _cache[1]
 
         # look up what we need to read
         text = None
@@ -1006,7 +1007,7 @@
 
         if iterrev == cachedrev:
             # cache hit
-            text = self._cache[2]
+            text = _cache[2]
         else:
             chain.append(iterrev)
         chain.reverse()