matrix sync: skip a member's remaining rooms after a transport error
ci/woodpecker/push/woodpecker Pipeline was canceled

An unreachable remote homeserver hangs every invite POST to that member until
the client timeout (8 rooms x 30s), which outlived the 5-minute service-sync
tick and starved every member queued behind it. Raise a member-scoped
_TransportError instead of returning False, skip that member's remaining rooms
for this pass, and report transport_skipped in the result. Invites stay
idempotent, so the next pass retries.

Test: a timed-out member is attempted once, not once per room.
This commit is contained in:
inference-admin committed 2026-11-23 14:26:03 +00:00
1 parent d190aa7762
commit 419b1f4322
2 files changed
+39 -9

No files matched your search

+30 -7
View File
@@ -2285,6 +2285,13 @@ async def sync_matrix_space() -> dict:
super().__init__(f"retry_after_ms={wait_ms}")
self.wait_ms = wait_ms
class _TransportError(Exception):
"""The invite POST itself never got an answer (timeout/reset)."""
def __init__(self, kind):
super().__init__(kind)
self.kind = kind
async def invite(mxid: str, room: str) -> bool:
try:
r = await client.post(
@@ -2293,14 +2300,16 @@ async def sync_matrix_space() -> dict:
)
except httpx.HTTPError as exc:
# A transport failure (read timeout, connection reset) belongs to
# ONE member/room, not to the sync. Synapse federates some invites
# and can exceed the read timeout. Swallow it, log it, let the next
# pass retry: raising here aborted the whole pass and silently
# skipped every member after this one, which is how a new member
# sat uninvited for a day.
# ONE member, not to the sync. Synapse federates some invites and
# can exceed the read timeout. Raise a member-scoped error so the
# caller can skip this member's REMAINING rooms: a remote homeserver
# that cannot be reached hangs every room until the client timeout
# (8 x 30s), which outlived the scheduled tick and starved every
# member queued behind it. Invites are idempotent; the next pass
# retries.
logger.warning("Matrix invite %s -> %s transport error: %s",
mxid, room, type(exc).__name__)
return False
raise _TransportError(type(exc).__name__) from exc
if r.status_code == 200:
return True
if r.status_code == 429:
@@ -2319,6 +2328,7 @@ async def sync_matrix_space() -> dict:
rooms = member_invite_rooms()
invited_count = 0
rate_limited = False
transport_skipped = 0
async with httpx.AsyncClient(timeout=30) as client:
# Snapshot EVERY room's membership once, up front: who is joined and who
@@ -2379,6 +2389,18 @@ async def sync_matrix_space() -> dict:
sent_any = True
if sent_any:
invited_count += 1
except _TransportError as exc:
# One member's federation timeout must not cost the pass their
# remaining rooms. An unreachable remote homeserver hangs EVERY
# room's invite until the client timeout, so retrying room by
# room burns the whole tick and the members queued behind this
# one never get invited. Skip this member and move on; invites
# are idempotent and the next pass retries.
transport_skipped += 1
logger.info(
"Matrix sync: %s transport error (%s); skipping their remaining "
"rooms this pass", mxid, exc.kind)
continue
except _RateLimited as exc:
rate_limited = True
logger.info(
@@ -2466,7 +2488,8 @@ async def sync_matrix_space() -> dict:
local_mxid, room, type(exc).__name__)
if retired:
logger.info("Matrix sync: retired %s local account(s)/invite(s)", retired)
return {"invited": invited_count, "rate_limited": rate_limited}
return {"invited": invited_count, "rate_limited": rate_limited,
"transport_skipped": transport_skipped}
async def matrix_member_mxids(client: httpx.AsyncClient):