Skip to content

Commit 8b1072c

Browse files
committed
Clamp stream_ordering to 0 instead of asserting
1 parent e288ebb commit 8b1072c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

synapse/storage/databases/main/thread_subscriptions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ def _should_skip_autosubscription_after_unsubscription(
130130
Returns:
131131
True if the automatic subscription should be skipped
132132
"""
133-
# these two orderings should be positive, because they don't refer to a specific event
134-
# but rather the maximum at the time of unsubscription
135-
assert unsubscribed_at.stream > 0
133+
# For normal rooms, these two orderings should be positive, because
134+
# they don't refer to a specific event but rather the maximum at the
135+
# time of unsubscription.
136+
# However, for rooms that have never been joined and that are being peeked at,
137+
# we might not have a single non-backfilled event and therefore the stream
138+
# ordering might be negative.
139+
# In this case, we clamp it at zero and ensure we fall back to
140+
# using topological ordering.
141+
unsubscribed_at = attr.evolve(
142+
unsubscribed_at, stream=max(0, unsubscribed_at.stream)
143+
)
136144
assert unsubscribed_at.topological > 0
137145

138146
if unsubscribed_at.stream >= autosub.stream > 0:

0 commit comments

Comments
 (0)