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

Faster Room Joins: prevent Synapse from answering federated join requests for a room which it has not fully joined yet. #13416

Merged
merged 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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/13416.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster Room Joins: prevent Synapse from answering federated join requests for a room which it has not fully joined yet.
14 changes: 14 additions & 0 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,22 @@ async def _on_send_membership_event(
Codes.BAD_JSON,
)

# Note that get_room_version throws if the room does not exist here.
room_version = await self.store.get_room_version(room_id)

if await self.store.is_partial_state_room(room_id):
# If our server is still only partially joined, we can't give a complete
squahtx marked this conversation as resolved.
Show resolved Hide resolved
# response to send_join, so return a 404 as we would if we weren't in the
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
# room at all.
logger.info(
"Rejecting send_join to %s because it's a partial state room", room_id
)
raise SynapseError(
404,
"Unable to handle send_join right now; this server is not fully joined.",
errcode=Codes.NOT_FOUND,
)
squahtx marked this conversation as resolved.
Show resolved Hide resolved

if membership_type == Membership.KNOCK and not room_version.msc2403_knocking:
raise SynapseError(
403,
Expand Down
13 changes: 13 additions & 0 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,19 @@ async def on_make_join_request(
# (and return a 404 otherwise)
room_version = await self.store.get_room_version(room_id)

if await self.store.is_partial_state_room(room_id):
# If our server is still only partially joined, we can't give a complete
# response to make_join, so return a 404 as we would if we weren't in the
# room at all.
squahtx marked this conversation as resolved.
Show resolved Hide resolved
logger.info(
"Rejecting make_join to %s because it's a partial state room", room_id
)
raise SynapseError(
404,
"Unable to handle make_join right now; this server is not fully joined.",
errcode=Codes.NOT_FOUND,
)

# now check that we are *still* in the room
is_in_room = await self._event_auth_handler.check_host_in_room(
room_id, self.server_name
Expand Down