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

Commit a0101fc

Browse files
authored
Handle /backfill returning no events (#10133)
Fixes #10123
1 parent 0acb501 commit a0101fc

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

changelog.d/10133.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug when using workers where pagination requests failed if a remote server returned zero events from `/backfill`. Introduced in 1.35.0.

synapse/handlers/federation.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from http import HTTPStatus
2323
from typing import (
2424
TYPE_CHECKING,
25+
Collection,
2526
Dict,
2627
Iterable,
2728
List,
@@ -1364,11 +1365,12 @@ async def get_event(event_id: str):
13641365

13651366
event_infos.append(_NewEventInfo(event, None, auth))
13661367

1367-
await self._auth_and_persist_events(
1368-
destination,
1369-
room_id,
1370-
event_infos,
1371-
)
1368+
if event_infos:
1369+
await self._auth_and_persist_events(
1370+
destination,
1371+
room_id,
1372+
event_infos,
1373+
)
13721374

13731375
def _sanity_check_event(self, ev: EventBase) -> None:
13741376
"""
@@ -2077,7 +2079,7 @@ async def _auth_and_persist_events(
20772079
self,
20782080
origin: str,
20792081
room_id: str,
2080-
event_infos: Iterable[_NewEventInfo],
2082+
event_infos: Collection[_NewEventInfo],
20812083
backfilled: bool = False,
20822084
) -> None:
20832085
"""Creates the appropriate contexts and persists events. The events
@@ -2088,6 +2090,9 @@ async def _auth_and_persist_events(
20882090
Notifies about the events where appropriate.
20892091
"""
20902092

2093+
if not event_infos:
2094+
return
2095+
20912096
async def prep(ev_info: _NewEventInfo):
20922097
event = ev_info.event
20932098
with nested_logging_context(suffix=event.event_id):
@@ -2216,13 +2221,14 @@ async def _persist_auth_tree(
22162221
raise
22172222
events_to_context[e.event_id].rejected = RejectedReason.AUTH_ERROR
22182223

2219-
await self.persist_events_and_notify(
2220-
room_id,
2221-
[
2222-
(e, events_to_context[e.event_id])
2223-
for e in itertools.chain(auth_events, state)
2224-
],
2225-
)
2224+
if auth_events or state:
2225+
await self.persist_events_and_notify(
2226+
room_id,
2227+
[
2228+
(e, events_to_context[e.event_id])
2229+
for e in itertools.chain(auth_events, state)
2230+
],
2231+
)
22262232

22272233
new_event_context = await self.state_handler.compute_event_context(
22282234
event, old_state=state
@@ -3061,7 +3067,13 @@ async def persist_events_and_notify(
30613067
the same room.
30623068
backfilled: Whether these events are a result of
30633069
backfilling or not
3070+
3071+
Returns:
3072+
The stream ID after which all events have been persisted.
30643073
"""
3074+
if not event_and_contexts:
3075+
return self.store.get_current_events_token()
3076+
30653077
instance = self.config.worker.events_shard_config.get_instance(room_id)
30663078
if instance != self._instance_name:
30673079
# Limit the number of events sent over replication. We choose 200

0 commit comments

Comments
 (0)