Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Don't try and backfill the same room in parallel. (#10116)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erikjohnston authored Jun 4, 2021
1 parent c96ab31 commit a0cd8ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/10116.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where the server would attempt to fetch the same history in the room from a remote server multiple times in parallel.
8 changes: 8 additions & 0 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def __init__(self, hs: "HomeServer"):
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
Expand Down Expand Up @@ -1041,6 +1043,12 @@ async def maybe_backfill(
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:
Expand Down

0 comments on commit a0cd8ae

Please sign in to comment.