Skip to content

Commit 97d2738

Browse files
authored
Fix CPU and database spinning when retrying sending events to servers whilst at the same time purging those events. (#18499)
Fixes: #18491 Fix hotlooping due to skipped PDUs if there is still no progress to be made. This could bite if the event was purged since being skipped during catch-up. Signed-off-by: Olivier 'reivilibre <[email protected]>
1 parent 945e223 commit 97d2738

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

changelog.d/18499.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix CPU and database spinning when retrying sending events to servers whilst at the same time purging those events.

synapse/federation/sender/per_destination_queue.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def __init__(
129129

130130
# The stream_ordering of the most recent PDU that was discarded due to
131131
# being in catch-up mode.
132+
# Can be set to zero if no PDU has been discarded since the last time
133+
# we queried for new PDUs during catch-up.
132134
self._catchup_last_skipped: int = 0
133135

134136
# Cache of the last successfully-transmitted stream ordering for this
@@ -462,8 +464,18 @@ async def _catch_up_transmission_loop(self) -> None:
462464
# of a race condition, so we check that no new events have been
463465
# skipped due to us being in catch-up mode
464466

465-
if self._catchup_last_skipped > last_successful_stream_ordering:
467+
if (
468+
self._catchup_last_skipped != 0
469+
and self._catchup_last_skipped > last_successful_stream_ordering
470+
):
466471
# another event has been skipped because we were in catch-up mode
472+
# As an exception to this case: we can hit this branch if the
473+
# room has been purged whilst we have been looping.
474+
# In that case we avoid hot-looping by resetting the 'catch-up skipped
475+
# PDU' flag.
476+
# Then if there is still no progress to be made at the next iteration,
477+
# we can exit catch-up mode.
478+
self._catchup_last_skipped = 0
467479
continue
468480

469481
# we are done catching up!

0 commit comments

Comments
 (0)