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

Commit

Permalink
In _purge_history_txn, ensure that txn.fetchall has elements before…
Browse files Browse the repository at this point in the history
… accessing rows (#10690)

This change adds a check for row existence before accessing row element, this should fix issue #10669
Signed-off-by: Vasya Boytsov [email protected]
  • Loading branch information
Kokokokoka authored Sep 24, 2021
1 parent 90d9fc7 commit e704cc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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:
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

0 comments on commit e704cc2

Please sign in to comment.