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

Commit e8f24b6

Browse files
authored
_run_push_actions_and_persist_event: handle no min_depth (#11014)
Make sure that we correctly handle rooms where we do not yet have a `min_depth`, and also add some comments and logging.
1 parent 7d70582 commit e8f24b6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

changelog.d/11014.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some extra logging to the event persistence code.

synapse/handlers/federation_event.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async def on_receive_pdu(self, origin: str, pdu: EventBase) -> None:
214214

215215
if missing_prevs:
216216
# We only backfill backwards to the min depth.
217-
min_depth = await self.get_min_depth_for_context(pdu.room_id)
217+
min_depth = await self._store.get_min_depth(pdu.room_id)
218218
logger.debug("min_depth: %d", min_depth)
219219

220220
if min_depth is not None and pdu.depth > min_depth:
@@ -1696,16 +1696,27 @@ async def _run_push_actions_and_persist_event(
16961696
# persist_events_and_notify directly.)
16971697
assert not event.internal_metadata.outlier
16981698

1699-
try:
1700-
if (
1701-
not backfilled
1702-
and not context.rejected
1703-
and (await self._store.get_min_depth(event.room_id)) <= event.depth
1704-
):
1699+
if not backfilled and not context.rejected:
1700+
min_depth = await self._store.get_min_depth(event.room_id)
1701+
if min_depth is None or min_depth > event.depth:
1702+
# XXX richvdh 2021/10/07: I don't really understand what this
1703+
# condition is doing. I think it's trying not to send pushes
1704+
# for events that predate our join - but that's not really what
1705+
# min_depth means, and anyway ancient events are a more general
1706+
# problem.
1707+
#
1708+
# for now I'm just going to log about it.
1709+
logger.info(
1710+
"Skipping push actions for old event with depth %s < %s",
1711+
event.depth,
1712+
min_depth,
1713+
)
1714+
else:
17051715
await self._action_generator.handle_push_actions_for_event(
17061716
event, context
17071717
)
17081718

1719+
try:
17091720
await self.persist_events_and_notify(
17101721
event.room_id, [(event, context)], backfilled=backfilled
17111722
)
@@ -1837,6 +1848,3 @@ def _sanity_check_event(self, ev: EventBase) -> None:
18371848
len(ev.auth_event_ids()),
18381849
)
18391850
raise SynapseError(HTTPStatus.BAD_REQUEST, "Too many auth_events")
1840-
1841-
async def get_min_depth_for_context(self, context: str) -> int:
1842-
return await self._store.get_min_depth(context)

synapse/storage/databases/main/event_federation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ async def get_latest_event_ids_in_room(self, room_id: str) -> List[str]:
906906
desc="get_latest_event_ids_in_room",
907907
)
908908

909-
async def get_min_depth(self, room_id: str) -> int:
909+
async def get_min_depth(self, room_id: str) -> Optional[int]:
910910
"""For the given room, get the minimum depth we have seen for it."""
911911
return await self.db_pool.runInteraction(
912912
"get_min_depth", self._get_min_depth_interaction, room_id

0 commit comments

Comments
 (0)