summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorAlexander Udovichenko <udovichenko48@gmail.com>2024-11-05 21:08:17 +0300
committerGitHub <noreply@github.com>2024-11-05 12:08:17 -0600
commit211c31dbd77281d114b9f08ef61c867d56316e8c (patch)
tree7d341fb03d570baef0f4d5430e3255e4eec4c991 /synapse
parentAdd experimental support for MSC4222 (#17888) (diff)
downloadsynapse-211c31dbd77281d114b9f08ef61c867d56316e8c.tar.xz
Fix WheelTimer implementation that can expired timeout early (#17850)
When entries insert in the end of timer queue, then unnecessary entry
inserted (with duplicated key).
This can lead to some timeouts expired early and consume memory.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/util/wheel_timer.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/synapse/util/wheel_timer.py b/synapse/util/wheel_timer.py

index 44b109bdfd..95eb1d7185 100644 --- a/synapse/util/wheel_timer.py +++ b/synapse/util/wheel_timer.py
@@ -47,7 +47,6 @@ class WheelTimer(Generic[T]): """ self.bucket_size: int = bucket_size self.entries: List[_Entry[T]] = [] - self.current_tick: int = 0 def insert(self, now: int, obj: T, then: int) -> None: """Inserts object into timer. @@ -78,11 +77,10 @@ class WheelTimer(Generic[T]): self.entries[max(min_key, then_key) - min_key].elements.add(obj) return - next_key = now_key + 1 if self.entries: - last_key = self.entries[-1].end_key + last_key = self.entries[-1].end_key + 1 else: - last_key = next_key + last_key = now_key + 1 # Handle the case when `then` is in the past and `entries` is empty. then_key = max(last_key, then_key)