summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-04-02 11:10:25 +0100
committerErik Johnston <erik@matrix.org>2021-04-02 11:10:25 +0100
commit0fddb9aacd5600a58ef35c2214cd72d33a0ebed2 (patch)
tree0418cf22fb9c4af03799dd495073401a92715ff1
parentDon't limit (diff)
downloadsynapse-0fddb9aacd5600a58ef35c2214cd72d33a0ebed2.tar.xz
fix
-rw-r--r--synapse/util/caches/lrucache.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py
index 2ea4a63e5a..d0767c269d 100644
--- a/synapse/util/caches/lrucache.py
+++ b/synapse/util/caches/lrucache.py
@@ -176,13 +176,13 @@ class LruCache(Generic[KT, VT]):
 
         def evict():
             ten_minutes_ago = int(reactor.seconds()) - 10 * 60
+            todelete = list_root.prev_node
             while (
                 cache_len() > self.max_size
-                or 0 < list_root.prev_node.allocated_ts < ten_minutes_ago + 60
+                or 0 < todelete.allocated_ts < ten_minutes_ago + 60
             ):
-                todelete = list_root.prev_node
-
                 if 0 < todelete.allocated_ts < ten_minutes_ago:
+                    todelete = list_root.prev_node
                     continue
 
                 todelete = list_root.prev_node
@@ -194,6 +194,8 @@ class LruCache(Generic[KT, VT]):
                 if metrics:
                     metrics.inc_evictions(evicted_len)
 
+                todelete = list_root.prev_node
+
         def synchronized(f: FT) -> FT:
             @wraps(f)
             def inner(*args, **kwargs):