matrix sync: a transport error on one invite must not abort the pass
An httpx.ReadTimeout during an invite POST raised out of sync_matrix_space, so every member after the timed-out one got nothing and the service-sync log said only 'Matrix sync failed:' (httpx transport exceptions stringify to ''). One new member sat uninvited for a day that way. - invite(): catch httpx.HTTPError per member/room, log the type, return False - pass counts only members whose invite actually returned True - room-membership snapshot, the retire half and the Cloudron users walk no longer abort on a transport error; the unreadable room/member is skipped - service-sync now logs the exception TYPE (empty str(e) hid the cause) Regression in tests/test_service_invites.py section 7: a timed-out member does not stop the member after them, and the next pass retries them.
This commit is contained in:
1 parent
d7c812ba07
commit
a4b6aa5357
2 files changed
+133
-46
No files matched your search
@@ -73,6 +73,7 @@ ROOM_INVITED = {} # room -> set(mxid)
|
||||
UNREADABLE = set() # rooms whose joined_members 500s
|
||||
invites_sent = [] # (room, mxid)
|
||||
INVITE_429_FOR = set() # mxids whose invite comes back 429
|
||||
INVITE_TIMEOUT_FOR = set() # mxids whose invite POST raises httpx.ReadTimeout
|
||||
POSTS = [] # Loomio POST payloads
|
||||
|
||||
ROSTER = {} # Loomio roster: email -> membership id
|
||||
@@ -127,6 +128,8 @@ class FakeClient:
|
||||
async def post(self, url, headers=None, json=None):
|
||||
if "/invite" in url:
|
||||
mxid = (json or {}).get("user_id")
|
||||
if mxid in INVITE_TIMEOUT_FOR:
|
||||
raise httpx.ReadTimeout("timed out")
|
||||
if mxid in INVITE_429_FOR:
|
||||
return FakeResp(429, {"retry_after_ms": 300000},
|
||||
text='{"errcode":"M_LIMIT_EXCEEDED"}')
|
||||
@@ -295,6 +298,51 @@ async def main():
|
||||
m.mark_loomio_invited("e@x.org")
|
||||
check("pending: empty once every member is stamped", m._service_sync_pending() == [])
|
||||
|
||||
# --- 7. ONE MEMBER'S TRANSPORT TIMEOUT MUST NOT KILL THE PASS ---------
|
||||
# A ReadTimeout on ONE invite used to abort the whole sync: every member
|
||||
# after the timed-out one silently got nothing, and the log line carried an
|
||||
# empty message. Two members need invites; the FIRST times out.
|
||||
global INVITE_TIMEOUT_FOR
|
||||
conn = m.get_db()
|
||||
for email, stamp in (("t@x.org", "2026-01-01 00:00:00"), ("u@x.org", "2026-01-01 00:00:00")):
|
||||
conn.execute("INSERT OR REPLACE INTO members (email, active, loomio_invited_at) VALUES (?, 1, ?)",
|
||||
(email, stamp))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
USERS["t@x.org"] = "tmember"
|
||||
USERS["u@x.org"] = "umember"
|
||||
|
||||
async def active_with_tu():
|
||||
return ["t@x.org", "u@x.org"]
|
||||
m.get_active_member_emails = active_with_tu
|
||||
ROOM_JOINED = {r_: set() for r_ in ROOMS}
|
||||
ROOM_INVITED = {r_: set() for r_ in ROOMS}
|
||||
INVITE_TIMEOUT_FOR = {"@tmember:inference.coop"}
|
||||
reset()
|
||||
r = await m.sync_matrix_space()
|
||||
check("timeout: a transport timeout does not raise out of the pass", isinstance(r, dict))
|
||||
check("timeout: the member AFTER the timed-out one is still invited",
|
||||
{room for room, _ in invites_sent} == set(ROOMS)
|
||||
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)
|
||||
|
||||
# The next pass retries the timed-out member (invites are idempotent).
|
||||
INVITE_TIMEOUT_FOR = set()
|
||||
reset()
|
||||
await m.sync_matrix_space()
|
||||
check("timeout: the next pass sends the timed-out member's invites",
|
||||
len(invites_sent) == 3 and all(mx == "@tmember:inference.coop" for _, mx in invites_sent))
|
||||
|
||||
# Clean up so the endpoint checks see a steady state.
|
||||
conn = m.get_db()
|
||||
conn.execute("DELETE FROM members WHERE email IN ('t@x.org', 'u@x.org')")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
INVITE_TIMEOUT_FOR = set()
|
||||
m.get_active_member_emails = _active
|
||||
ROOM_JOINED = {r_: set() for r_ in ROOMS}
|
||||
ROOM_INVITED = {r_: set() for r_ in ROOMS}
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
|
||||
Reference in new issue
Block a user