matrix sync: skip a member's remaining rooms after a transport error
ci/woodpecker/push/woodpecker Pipeline was canceled
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:
1 parent
d190aa7762
commit
419b1f4322
2 files changed
+39
-9
No files matched your search
+30
-7
@@ -2285,6 +2285,13 @@ async def sync_matrix_space() -> dict:
|
|||||||
super().__init__(f"retry_after_ms={wait_ms}")
|
super().__init__(f"retry_after_ms={wait_ms}")
|
||||||
self.wait_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:
|
async def invite(mxid: str, room: str) -> bool:
|
||||||
try:
|
try:
|
||||||
r = await client.post(
|
r = await client.post(
|
||||||
@@ -2293,14 +2300,16 @@ async def sync_matrix_space() -> dict:
|
|||||||
)
|
)
|
||||||
except httpx.HTTPError as exc:
|
except httpx.HTTPError as exc:
|
||||||
# A transport failure (read timeout, connection reset) belongs to
|
# A transport failure (read timeout, connection reset) belongs to
|
||||||
# ONE member/room, not to the sync. Synapse federates some invites
|
# ONE member, not to the sync. Synapse federates some invites and
|
||||||
# and can exceed the read timeout. Swallow it, log it, let the next
|
# can exceed the read timeout. Raise a member-scoped error so the
|
||||||
# pass retry: raising here aborted the whole pass and silently
|
# caller can skip this member's REMAINING rooms: a remote homeserver
|
||||||
# skipped every member after this one, which is how a new member
|
# that cannot be reached hangs every room until the client timeout
|
||||||
# sat uninvited for a day.
|
# (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",
|
logger.warning("Matrix invite %s -> %s transport error: %s",
|
||||||
mxid, room, type(exc).__name__)
|
mxid, room, type(exc).__name__)
|
||||||
return False
|
raise _TransportError(type(exc).__name__) from exc
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return True
|
return True
|
||||||
if r.status_code == 429:
|
if r.status_code == 429:
|
||||||
@@ -2319,6 +2328,7 @@ async def sync_matrix_space() -> dict:
|
|||||||
rooms = member_invite_rooms()
|
rooms = member_invite_rooms()
|
||||||
invited_count = 0
|
invited_count = 0
|
||||||
rate_limited = False
|
rate_limited = False
|
||||||
|
transport_skipped = 0
|
||||||
|
|
||||||
async with httpx.AsyncClient(timeout=30) as client:
|
async with httpx.AsyncClient(timeout=30) as client:
|
||||||
# Snapshot EVERY room's membership once, up front: who is joined and who
|
# 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
|
sent_any = True
|
||||||
if sent_any:
|
if sent_any:
|
||||||
invited_count += 1
|
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:
|
except _RateLimited as exc:
|
||||||
rate_limited = True
|
rate_limited = True
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -2466,7 +2488,8 @@ async def sync_matrix_space() -> dict:
|
|||||||
local_mxid, room, type(exc).__name__)
|
local_mxid, room, type(exc).__name__)
|
||||||
if retired:
|
if retired:
|
||||||
logger.info("Matrix sync: retired %s local account(s)/invite(s)", 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):
|
async def matrix_member_mxids(client: httpx.AsyncClient):
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ UNREADABLE = set() # rooms whose joined_members 500s
|
|||||||
invites_sent = [] # (room, mxid)
|
invites_sent = [] # (room, mxid)
|
||||||
INVITE_429_FOR = set() # mxids whose invite comes back 429
|
INVITE_429_FOR = set() # mxids whose invite comes back 429
|
||||||
INVITE_TIMEOUT_FOR = set() # mxids whose invite POST raises httpx.ReadTimeout
|
INVITE_TIMEOUT_FOR = set() # mxids whose invite POST raises httpx.ReadTimeout
|
||||||
|
TIMEOUT_ATTEMPTS = [] # (room, mxid) for every POST that timed out
|
||||||
POSTS = [] # Loomio POST payloads
|
POSTS = [] # Loomio POST payloads
|
||||||
|
|
||||||
ROSTER = {} # Loomio roster: email -> membership id
|
ROSTER = {} # Loomio roster: email -> membership id
|
||||||
@@ -129,6 +130,7 @@ class FakeClient:
|
|||||||
if "/invite" in url:
|
if "/invite" in url:
|
||||||
mxid = (json or {}).get("user_id")
|
mxid = (json or {}).get("user_id")
|
||||||
if mxid in INVITE_TIMEOUT_FOR:
|
if mxid in INVITE_TIMEOUT_FOR:
|
||||||
|
TIMEOUT_ATTEMPTS.append((url, mxid))
|
||||||
raise httpx.ReadTimeout("timed out")
|
raise httpx.ReadTimeout("timed out")
|
||||||
if mxid in INVITE_429_FOR:
|
if mxid in INVITE_429_FOR:
|
||||||
return FakeResp(429, {"retry_after_ms": 300000},
|
return FakeResp(429, {"retry_after_ms": 300000},
|
||||||
@@ -165,6 +167,7 @@ def reset():
|
|||||||
global invites_sent
|
global invites_sent
|
||||||
invites_sent = []
|
invites_sent = []
|
||||||
POSTS.clear()
|
POSTS.clear()
|
||||||
|
TIMEOUT_ATTEMPTS.clear()
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
@@ -209,8 +212,8 @@ async def main():
|
|||||||
not any(mx == "@amember:inference.coop" for _, mx in invites_sent))
|
not any(mx == "@amember:inference.coop" for _, mx in invites_sent))
|
||||||
check("per-room: two members can be pending on different rooms",
|
check("per-room: two members can be pending on different rooms",
|
||||||
not any(mx == "@cmember:inference.coop" for _, mx in invites_sent))
|
not any(mx == "@cmember:inference.coop" for _, mx in invites_sent))
|
||||||
check("return shape: the result carries invited + rate_limited",
|
check("return shape: the result carries invited + rate_limited + transport_skipped",
|
||||||
set(r) == {"invited", "rate_limited"} and r["rate_limited"] is False)
|
set(r) == {"invited", "rate_limited", "transport_skipped"} and r["rate_limited"] is False)
|
||||||
|
|
||||||
# --- 2. IDEMPOTENCE: a second pass sends nothing ----------------------
|
# --- 2. IDEMPOTENCE: a second pass sends nothing ----------------------
|
||||||
reset()
|
reset()
|
||||||
@@ -325,6 +328,10 @@ async def main():
|
|||||||
{room for room, _ in invites_sent} == set(ROOMS)
|
{room for room, _ in invites_sent} == set(ROOMS)
|
||||||
and all(mx == "@umember:inference.coop" for _, mx in invites_sent))
|
and all(mx == "@umember:inference.coop" for _, mx in invites_sent))
|
||||||
check("timeout: the timed-out member is not counted as invited", r["invited"] == 1)
|
check("timeout: the timed-out member is not counted as invited", r["invited"] == 1)
|
||||||
|
check("timeout: a timed-out member is attempted ONCE, not once per room",
|
||||||
|
len(TIMEOUT_ATTEMPTS) == 1)
|
||||||
|
check("timeout: the pass reports the member whose rooms it skipped",
|
||||||
|
r.get("transport_skipped") == 1)
|
||||||
|
|
||||||
# The next pass retries the timed-out member (invites are idempotent).
|
# The next pass retries the timed-out member (invites are idempotent).
|
||||||
INVITE_TIMEOUT_FOR = set()
|
INVITE_TIMEOUT_FOR = set()
|
||||||
|
|||||||
Reference in new issue
Block a user