summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-04-02 11:20:07 +0100
committerErik Johnston <erik@matrix.org>2021-04-02 11:20:07 +0100
commitd088695f15fec292f9c7834d28859d13c3013114 (patch)
tree0237271009531520948d9a569fe88e288b485c97
parentfix (diff)
downloadsynapse-d088695f15fec292f9c7834d28859d13c3013114.tar.xz
fix
-rw-r--r--synapse/util/caches/lrucache.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py
index d0767c269d..e0749ac8a2 100644
--- a/synapse/util/caches/lrucache.py
+++ b/synapse/util/caches/lrucache.py
@@ -176,25 +176,30 @@ class LruCache(Generic[KT, VT]):
 
         def evict():
             ten_minutes_ago = int(reactor.seconds()) - 10 * 60
+            while cache_len() > self.max_size:
+                todelete = list_root.prev_node
+                evicted_len = delete_node(todelete)
+                cache.pop(todelete.key, None)
+                if metrics:
+                    metrics.inc_evictions(evicted_len)
+
             todelete = list_root.prev_node
-            while (
-                cache_len() > self.max_size
-                or 0 < todelete.allocated_ts < ten_minutes_ago + 60
-            ):
+            while 0 < todelete.allocated_ts < ten_minutes_ago + 60:
+                if list_root == todelete:
+                    break
+
                 if 0 < todelete.allocated_ts < ten_minutes_ago:
-                    todelete = list_root.prev_node
+                    todelete = todelete.prev_node
                     continue
 
-                todelete = list_root.prev_node
-                if list_root == todelete:
-                    break
+                next_todelete = todelete.prev_node
 
                 evicted_len = delete_node(todelete)
                 cache.pop(todelete.key, None)
                 if metrics:
                     metrics.inc_evictions(evicted_len)
 
-                todelete = list_root.prev_node
+                todelete = next_todelete
 
         def synchronized(f: FT) -> FT:
             @wraps(f)