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

Don't try and backfill the same room in parallel. #10116

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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