This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 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(
731731 # straight back in again
732732
733733 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 )
737740 except BodyExceededMaxSize :
738741 raise SynapseError (
739742 HTTPStatus .BAD_GATEWAY ,
740743 "Requested file is too large > %r bytes" % (max_size ,),
741744 Codes .TOO_LARGE ,
742745 )
746+ except defer .TimeoutError :
747+ raise SynapseError (
748+ HTTPStatus .BAD_GATEWAY ,
749+ "Requested file took too long to download" ,
750+ Codes .TOO_LARGE ,
751+ )
743752 except Exception as e :
744753 raise SynapseError (
745754 HTTPStatus .BAD_GATEWAY , ("Failed to download remote body: %s" % e )
You can’t perform that action at this time.
0 commit comments