From 148f46620f52c12b7fea26ef696e96ce91efdb88 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:19:58 -0700 Subject: [PATCH] fix(matrix): add backoff for SyncError in sync loop (#3280) When the homeserver returns an error response, matrix-nio parses it as a SyncError return value rather than raising an exception. The sync loop only had backoff in the except handler, so SyncError caused a tight retry loop (~489 req/s) flooding logs and hammering the homeserver. Check the return value and sleep 5s before retry. Cherry-picked from PR #2937 by ticketclosed-wontfix. Co-authored-by: ticketclosed-wontfix --- gateway/platforms/matrix.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index d353b8294..79ac82396 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -551,9 +551,20 @@ class MatrixAdapter(BasePlatformAdapter): async def _sync_loop(self) -> None: """Continuously sync with the homeserver.""" + import nio + while not self._closing: try: - await self._client.sync(timeout=30000) + resp = await self._client.sync(timeout=30000) + if isinstance(resp, nio.SyncError): + if self._closing: + return + logger.warning( + "Matrix: sync returned %s: %s — retrying in 5s", + type(resp).__name__, + getattr(resp, "message", resp), + ) + await asyncio.sleep(5) except asyncio.CancelledError: return except Exception as exc: