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

Commit 9408b86

Browse files
baboliviererikjohnston
authored andcommitted
Limit the number of events sent over replication when persisting events. (#10082)
1 parent 1641c5c commit 9408b86

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

changelog.d/10082.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a bug causing replication requests to fail when receiving a lot of events via federation.

synapse/handlers/federation.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
get_domain_from_id,
9292
)
9393
from synapse.util.async_helpers import Linearizer, concurrently_execute
94+
from synapse.util.iterutils import batch_iter
9495
from synapse.util.retryutils import NotRetryingDestination
9596
from synapse.util.stringutils import shortstr
9697
from synapse.visibility import filter_events_for_server
@@ -3053,13 +3054,15 @@ async def persist_events_and_notify(
30533054
"""
30543055
instance = self.config.worker.events_shard_config.get_instance(room_id)
30553056
if instance != self._instance_name:
3056-
result = await self._send_events(
3057-
instance_name=instance,
3058-
store=self.store,
3059-
room_id=room_id,
3060-
event_and_contexts=event_and_contexts,
3061-
backfilled=backfilled,
3062-
)
3057+
# Limit the number of events sent over federation.
3058+
for batch in batch_iter(event_and_contexts, 1000):
3059+
result = await self._send_events(
3060+
instance_name=instance,
3061+
store=self.store,
3062+
room_id=room_id,
3063+
event_and_contexts=batch,
3064+
backfilled=backfilled,
3065+
)
30633066
return result["max_stream_id"]
30643067
else:
30653068
assert self.storage.persistence

0 commit comments

Comments
 (0)