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

Commit b38bdae

Browse files
authored
Fix AssertionErrors after purging events (#11642)
* Fix AssertionErrors after purging events If you purged a bunch of events from your database, and then restarted synapse without receiving more events, then you would get a bunch of AssertionErrors on restart. This fixes the situation by rewinding the stream processors. * `check-newsfragment`: ignore deleted newsfiles
1 parent 878aa55 commit b38bdae

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

changelog.d/11536.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug which could cause `AssertionError`s to be written to the log when Synapse was restarted after purging events from the database.

changelog.d/11536.misc

-1
This file was deleted.

changelog.d/11642.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug which could cause `AssertionError`s to be written to the log when Synapse was restarted after purging events from the database.

scripts-dev/check-newsfragment

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ echo "--------------------------"
4242
echo
4343

4444
matched=0
45-
for f in $(git diff --name-only FETCH_HEAD... -- changelog.d); do
46-
# check that any modified newsfiles on this branch end with a full stop.
45+
for f in $(git diff --diff-filter=d --name-only FETCH_HEAD... -- changelog.d); do
46+
# check that any added newsfiles on this branch end with a full stop.
4747
lastchar=$(tr -d '\n' < "$f" | tail -c 1)
4848
if [ "$lastchar" != '.' ] && [ "$lastchar" != '!' ]; then
4949
echo -e "\e[31mERROR: newsfragment $f does not end with a '.' or '!'\e[39m" >&2

synapse/handlers/stats.py

+11
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ async def _unsafe_process(self) -> None:
8080
# If self.pos is None then means we haven't fetched it from DB
8181
if self.pos is None:
8282
self.pos = await self.store.get_stats_positions()
83+
room_max_stream_ordering = self.store.get_room_max_stream_ordering()
84+
if self.pos > room_max_stream_ordering:
85+
# apparently, we've processed more events than exist in the database!
86+
# this can happen if events are removed with history purge or similar.
87+
logger.warning(
88+
"Event stream ordering appears to have gone backwards (%i -> %i): "
89+
"rewinding stats processor",
90+
self.pos,
91+
room_max_stream_ordering,
92+
)
93+
self.pos = room_max_stream_ordering
8394

8495
# Loop round handling deltas until we're up to date
8596

synapse/handlers/user_directory.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,21 @@ async def _unsafe_process(self) -> None:
148148
if self.pos is None:
149149
self.pos = await self.store.get_user_directory_stream_pos()
150150

151-
# If still None then the initial background update hasn't happened yet.
152-
if self.pos is None:
153-
return None
151+
# If still None then the initial background update hasn't happened yet.
152+
if self.pos is None:
153+
return None
154+
155+
room_max_stream_ordering = self.store.get_room_max_stream_ordering()
156+
if self.pos > room_max_stream_ordering:
157+
# apparently, we've processed more events than exist in the database!
158+
# this can happen if events are removed with history purge or similar.
159+
logger.warning(
160+
"Event stream ordering appears to have gone backwards (%i -> %i): "
161+
"rewinding user directory processor",
162+
self.pos,
163+
room_max_stream_ordering,
164+
)
165+
self.pos = room_max_stream_ordering
154166

155167
# Loop round handling deltas until we're up to date
156168
while True:

0 commit comments

Comments
 (0)