summary refs log tree commit diff
path: root/synapse/federation/federation_server.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-08-02 14:37:25 +0100
committerGitHub <noreply@github.com>2021-08-02 13:37:25 +0000
commit01d45fe964d323e7f66358c2db57d00a44bf2274 (patch)
tree738e1198533a9f6e9a29df6c5aa42e7c9ee4ee49 /synapse/federation/federation_server.py
parentAllow setting transaction limit for db connections (#10440) (diff)
downloadsynapse-01d45fe964d323e7f66358c2db57d00a44bf2274.tar.xz
Prune inbound federation queues if they get too long (#10390)
Diffstat (limited to 'synapse/federation/federation_server.py')
-rw-r--r--synapse/federation/federation_server.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py
index 2892a11d7d..145b9161d9 100644
--- a/synapse/federation/federation_server.py
+++ b/synapse/federation/federation_server.py
@@ -1024,6 +1024,23 @@ class FederationServer(FederationBase):
 
             origin, event = next
 
+            # Prune the event queue if it's getting large.
+            #
+            # We do this *after* handling the first event as the common case is
+            # that the queue is empty (/has the single event in), and so there's
+            # no need to do this check.
+            pruned = await self.store.prune_staged_events_in_room(room_id, room_version)
+            if pruned:
+                # If we have pruned the queue check we need to refetch the next
+                # event to handle.
+                next = await self.store.get_next_staged_event_for_room(
+                    room_id, room_version
+                )
+                if not next:
+                    break
+
+                origin, event = next
+
             lock = await self.store.try_acquire_lock(
                 _INBOUND_EVENT_HANDLING_LOCK_NAME, room_id
             )