This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Commit 02d99f0 1 parent ec2271a commit 02d99f0 Copy full SHA for 02d99f0
File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change
1
+ Fix a long-standing bug that media streams could cause long-lived connections when generating URL previews.
Original file line number Diff line number Diff line change @@ -731,15 +731,24 @@ async def get_file(
731
731
# straight back in again
732
732
733
733
try :
734
- length = await make_deferred_yieldable (
735
- read_body_with_max_size (response , output_stream , max_size )
736
- )
734
+ d = read_body_with_max_size (response , output_stream , max_size )
735
+
736
+ # Ensure that the body is not read forever.
737
+ d = timeout_deferred (d , 30 , self .hs .get_reactor ())
738
+
739
+ length = await make_deferred_yieldable (d )
737
740
except BodyExceededMaxSize :
738
741
raise SynapseError (
739
742
HTTPStatus .BAD_GATEWAY ,
740
743
"Requested file is too large > %r bytes" % (max_size ,),
741
744
Codes .TOO_LARGE ,
742
745
)
746
+ except defer .TimeoutError :
747
+ raise SynapseError (
748
+ HTTPStatus .BAD_GATEWAY ,
749
+ "Requested file took too long to download" ,
750
+ Codes .TOO_LARGE ,
751
+ )
743
752
except Exception as e :
744
753
raise SynapseError (
745
754
HTTPStatus .BAD_GATEWAY , ("Failed to download remote body: %s" % e )
You can’t perform that action at this time.
0 commit comments