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

In _purge_history_txn, ensure that txn.fetchall has elements before accessing rows #10690

Merged
merged 7 commits into from
Sep 24, 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/10690.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug that caused an `AssertionError` when purging history in certain rooms. Contributed by @Kokokokoka.
22 changes: 13 additions & 9 deletions synapse/storage/databases/main/purge_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,19 @@ def _purge_history_txn(
(room_id,),
)
rows = txn.fetchall()
max_depth = max(row[1] for row in rows)

if max_depth < token.topological:
# We need to ensure we don't delete all the events from the database
# otherwise we wouldn't be able to send any events (due to not
# having any backwards extremities)
raise SynapseError(
400, "topological_ordering is greater than forward extremeties"
)
# if we already have no forwards extremities (for example because they were
# cleared out by the `delete_old_current_state_events` background database
# update), then we may as well carry on.
if rows:
richvdh marked this conversation as resolved.
Show resolved Hide resolved
richvdh marked this conversation as resolved.
Show resolved Hide resolved
max_depth = max(row[1] for row in rows)

if max_depth < token.topological:
# We need to ensure we don't delete all the events from the database
# otherwise we wouldn't be able to send any events (due to not
# having any backwards extremities)
raise SynapseError(
400, "topological_ordering is greater than forward extremities"
)

logger.info("[purge] looking for events to delete")

Expand Down