Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix error when sending message into deleted room. #15235

Merged
merged 7 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15235.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix long-standing error when sending message into deleted room.
17 changes: 15 additions & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,11 @@ async def create_and_send_nonmember_event(
# a situation where event persistence can't keep up, causing
# extremities to pile up, which in turn leads to state resolution
# taking longer.
async with self.limiter.queue(event_dict["room_id"]):
room_id = event_dict["room_id"]
async with self.limiter.queue(room_id):
if txn_id:
event = await self.get_event_from_transaction(
requester, txn_id, event_dict["room_id"]
requester, txn_id, room_id
)
if event:
# we know it was persisted, so must have a stream ordering
Expand All @@ -1000,6 +1001,18 @@ async def create_and_send_nonmember_event(
event.internal_metadata.stream_ordering,
)

# If we don't have any prev event IDs specified then we need to
# check that the host is in the room (as otherwise populating the
# prev events will fail), at which point we may as well check the
# local user is in the room.
if not prev_event_ids:
user_id = requester.user.to_string()
is_user_in_room = await self.store.check_local_user_in_room(
user_id, room_id
)
if not is_user_in_room:
raise AuthError(403, f"User {user_id} not in room {room_id}")

# Try several times, it could fail with PartialStateConflictError
# in handle_new_client_event, cf comment in except block.
max_retries = 5
Expand Down