1 files changed, 12 insertions, 3 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index ca33b45cb2..743a7ffcb1 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -731,15 +731,24 @@ class SimpleHttpClient:
# straight back in again
try:
- length = await make_deferred_yieldable(
- read_body_with_max_size(response, output_stream, max_size)
- )
+ d = read_body_with_max_size(response, output_stream, max_size)
+
+ # Ensure that the body is not read forever.
+ d = timeout_deferred(d, 30, self.hs.get_reactor())
+
+ length = await make_deferred_yieldable(d)
except BodyExceededMaxSize:
raise SynapseError(
HTTPStatus.BAD_GATEWAY,
"Requested file is too large > %r bytes" % (max_size,),
Codes.TOO_LARGE,
)
+ except defer.TimeoutError:
+ raise SynapseError(
+ HTTPStatus.BAD_GATEWAY,
+ "Requested file took too long to download",
+ Codes.TOO_LARGE,
+ )
except Exception as e:
raise SynapseError(
HTTPStatus.BAD_GATEWAY, ("Failed to download remote body: %s" % e)
|