Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
4084a774
Commit
4084a774
authored
6 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Timeout reading body for outbound HTTP requests
parent
b0411154
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/http/matrixfederationclient.py
+45
-7
45 additions, 7 deletions
synapse/http/matrixfederationclient.py
with
45 additions
and
7 deletions
synapse/http/matrixfederationclient.py
+
45
−
7
View file @
4084a774
...
...
@@ -280,7 +280,10 @@ class MatrixFederationHttpClient(object):
# :'(
# Update transactions table?
with
logcontext
.
PreserveLoggingContext
():
body
=
yield
treq
.
content
(
response
)
body
=
yield
self
.
_timeout_deferred
(
treq
.
content
(
response
),
timeout
,
)
raise
HttpResponseException
(
response
.
code
,
response
.
phrase
,
body
)
...
...
@@ -394,7 +397,10 @@ class MatrixFederationHttpClient(object):
check_content_type_is_json
(
response
.
headers
)
with
logcontext
.
PreserveLoggingContext
():
body
=
yield
treq
.
json_content
(
response
)
body
=
yield
self
.
_timeout_deferred
(
treq
.
json_content
(
response
),
timeout
,
)
defer
.
returnValue
(
body
)
@defer.inlineCallbacks
...
...
@@ -444,7 +450,10 @@ class MatrixFederationHttpClient(object):
check_content_type_is_json
(
response
.
headers
)
with
logcontext
.
PreserveLoggingContext
():
body
=
yield
treq
.
json_content
(
response
)
body
=
yield
self
.
_timeout_deferred
(
treq
.
json_content
(
response
),
timeout
,
)
defer
.
returnValue
(
body
)
...
...
@@ -496,7 +505,10 @@ class MatrixFederationHttpClient(object):
check_content_type_is_json
(
response
.
headers
)
with
logcontext
.
PreserveLoggingContext
():
body
=
yield
treq
.
json_content
(
response
)
body
=
yield
self
.
_timeout_deferred
(
treq
.
json_content
(
response
),
timeout
,
)
defer
.
returnValue
(
body
)
...
...
@@ -543,7 +555,10 @@ class MatrixFederationHttpClient(object):
check_content_type_is_json
(
response
.
headers
)
with
logcontext
.
PreserveLoggingContext
():
body
=
yield
treq
.
json_content
(
response
)
body
=
yield
self
.
_timeout_deferred
(
treq
.
json_content
(
response
),
timeout
,
)
defer
.
returnValue
(
body
)
...
...
@@ -585,8 +600,10 @@ class MatrixFederationHttpClient(object):
try
:
with
logcontext
.
PreserveLoggingContext
():
length
=
yield
_readBodyToFile
(
response
,
output_stream
,
max_size
length
=
yield
self
.
_timeout_deferred
(
_readBodyToFile
(
response
,
output_stream
,
max_size
),
)
except
Exception
:
logger
.
exception
(
"
Failed to download body
"
)
...
...
@@ -594,6 +611,27 @@ class MatrixFederationHttpClient(object):
defer
.
returnValue
((
length
,
headers
))
def
_timeout_deferred
(
self
,
deferred
,
timeout_ms
=
None
):
"""
Times the deferred out after `timeout_ms` ms
Args:
deferred (Deferred)
timeout_ms (int|None): Timeout in milliseconds. If None defaults
to 60 seconds.
Returns:
Deferred
"""
add_timeout_to_deferred
(
deferred
,
timeout_ms
/
1000.
if
timeout_ms
else
60
,
self
.
hs
.
get_reactor
(),
cancelled_to_request_timed_out_error
,
)
return
deferred
class
_ReadBodyToFileProtocol
(
protocol
.
Protocol
):
def
__init__
(
self
,
stream
,
deferred
,
max_size
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment