summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-06-04 10:47:58 +0100
committerGitHub <noreply@github.com>2021-06-04 10:47:58 +0100
commita0cd8ae8cbe14d2821cbe8fd6b011c4ddc729344 (patch)
treefb5a989c56673fec29d2e84a4043c02fda7aeeb9 /synapse/handlers
parentLimit number of events in a replication request (#10118) (diff)
downloadsynapse-a0cd8ae8cbe14d2821cbe8fd6b011c4ddc729344.tar.xz
Don't try and backfill the same room in parallel. (#10116)
If backfilling is slow then the client may time out and retry, causing
Synapse to start a new `/backfill` before the existing backfill has
finished, duplicating work.
Diffstat (limited to '')
-rw-r--r--synapse/handlers/federation.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index f3f97db2fa..b802822baa 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -178,6 +178,8 @@ class FederationHandler(BaseHandler):
         self.room_queues = {}  # type: Dict[str, List[Tuple[EventBase, str]]]
         self._room_pdu_linearizer = Linearizer("fed_room_pdu")
 
+        self._room_backfill = Linearizer("room_backfill")
+
         self.third_party_event_rules = hs.get_third_party_event_rules()
 
         self._ephemeral_messages_enabled = hs.config.enable_ephemeral_messages
@@ -1041,6 +1043,12 @@ class FederationHandler(BaseHandler):
                 return. This is used as part of the heuristic to decide if we
                 should back paginate.
         """
+        with (await self._room_backfill.queue(room_id)):
+            return await self._maybe_backfill_inner(room_id, current_depth, limit)
+
+    async def _maybe_backfill_inner(
+        self, room_id: str, current_depth: int, limit: int
+    ) -> bool:
         extremities = await self.store.get_oldest_events_with_depth_in_room(room_id)
 
         if not extremities: