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 4 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 @@
Ensure that a room has forward extremities before attempting to purging historical events.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 10 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,16 @@ 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 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