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

Commit 84cf3e4

Browse files
authored
Allow response of /send_join to be larger. (#10093)
Fixes #10087.
1 parent 8e15c92 commit 84cf3e4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

changelog.d/10093.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix HTTP response size limit to allow joining very large rooms over federation.

synapse/federation/transport/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535

3636
logger = logging.getLogger(__name__)
3737

38+
# Send join responses can be huge, so we set a separate limit here. The response
39+
# is parsed in a streaming manner, which helps alleviate the issue of memory
40+
# usage a bit.
41+
MAX_RESPONSE_SIZE_SEND_JOIN = 500 * 1024 * 1024
42+
3843

3944
class TransportLayerClient:
4045
"""Sends federation HTTP requests to other servers"""
@@ -261,6 +266,7 @@ async def send_join_v1(
261266
path=path,
262267
data=content,
263268
parser=SendJoinParser(room_version, v1_api=True),
269+
max_response_size=MAX_RESPONSE_SIZE_SEND_JOIN,
264270
)
265271

266272
return response
@@ -276,6 +282,7 @@ async def send_join_v2(
276282
path=path,
277283
data=content,
278284
parser=SendJoinParser(room_version, v1_api=False),
285+
max_response_size=MAX_RESPONSE_SIZE_SEND_JOIN,
279286
)
280287

281288
return response

synapse/http/matrixfederationclient.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ async def _handle_response(
205205
response: IResponse,
206206
start_ms: int,
207207
parser: ByteParser[T],
208+
max_response_size: Optional[int] = None,
208209
) -> T:
209210
"""
210211
Reads the body of a response with a timeout and sends it to a parser
@@ -216,15 +217,20 @@ async def _handle_response(
216217
response: response to the request
217218
start_ms: Timestamp when request was made
218219
parser: The parser for the response
220+
max_response_size: The maximum size to read from the response, if None
221+
uses the default.
219222
220223
Returns:
221224
The parsed response
222225
"""
223226

227+
if max_response_size is None:
228+
max_response_size = MAX_RESPONSE_SIZE
229+
224230
try:
225231
check_content_type_is(response.headers, parser.CONTENT_TYPE)
226232

227-
d = read_body_with_max_size(response, parser, MAX_RESPONSE_SIZE)
233+
d = read_body_with_max_size(response, parser, max_response_size)
228234
d = timeout_deferred(d, timeout=timeout_sec, reactor=reactor)
229235

230236
length = await make_deferred_yieldable(d)
@@ -735,6 +741,7 @@ async def put_json(
735741
backoff_on_404: bool = False,
736742
try_trailing_slash_on_400: bool = False,
737743
parser: Literal[None] = None,
744+
max_response_size: Optional[int] = None,
738745
) -> Union[JsonDict, list]:
739746
...
740747

@@ -752,6 +759,7 @@ async def put_json(
752759
backoff_on_404: bool = False,
753760
try_trailing_slash_on_400: bool = False,
754761
parser: Optional[ByteParser[T]] = None,
762+
max_response_size: Optional[int] = None,
755763
) -> T:
756764
...
757765

@@ -768,6 +776,7 @@ async def put_json(
768776
backoff_on_404: bool = False,
769777
try_trailing_slash_on_400: bool = False,
770778
parser: Optional[ByteParser] = None,
779+
max_response_size: Optional[int] = None,
771780
):
772781
"""Sends the specified json data using PUT
773782
@@ -803,6 +812,8 @@ async def put_json(
803812
enabled.
804813
parser: The parser to use to decode the response. Defaults to
805814
parsing as JSON.
815+
max_response_size: The maximum size to read from the response, if None
816+
uses the default.
806817
807818
Returns:
808819
Succeeds when we get a 2xx HTTP response. The
@@ -853,6 +864,7 @@ async def put_json(
853864
response,
854865
start_ms,
855866
parser=parser,
867+
max_response_size=max_response_size,
856868
)
857869

858870
return body

0 commit comments

Comments
 (0)