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
0e6b3e4e
Commit
0e6b3e4e
authored
10 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Time out HTTP federation requests
parent
771892b3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/http/matrixfederationclient.py
+9
-2
9 additions, 2 deletions
synapse/http/matrixfederationclient.py
synapse/util/async.py
+20
-0
20 additions, 0 deletions
synapse/util/async.py
with
29 additions
and
2 deletions
synapse/http/matrixfederationclient.py
+
9
−
2
View file @
0e6b3e4e
...
...
@@ -22,7 +22,7 @@ from twisted.web._newclient import ResponseDone
from
synapse.http.agent_name
import
AGENT_NAME
from
synapse.http.endpoint
import
matrix_federation_endpoint
from
synapse.util.async
import
sleep
from
synapse.util.async
import
sleep
,
time_bound_deferred
from
synapse.util.logcontext
import
PreserveLoggingContext
from
syutil.jsonutil
import
encode_canonical_json
...
...
@@ -78,6 +78,7 @@ class MatrixFederationHttpClient(object):
self
.
signing_key
=
hs
.
config
.
signing_key
[
0
]
self
.
server_name
=
hs
.
hostname
self
.
agent
=
MatrixFederationHttpAgent
(
reactor
)
self
.
clock
=
hs
.
get_clock
()
@defer.inlineCallbacks
def
_create_request
(
self
,
destination
,
method
,
path_bytes
,
...
...
@@ -117,7 +118,7 @@ class MatrixFederationHttpClient(object):
try
:
with
PreserveLoggingContext
():
re
sponse
=
yield
self
.
agent
.
request
(
re
quest_deferred
=
self
.
agent
.
request
(
destination
,
endpoint
,
method
,
...
...
@@ -128,6 +129,12 @@ class MatrixFederationHttpClient(object):
producer
)
response
=
yield
time_bound_deferred
(
request_deferred
,
clock
=
self
.
clock
,
time_out
=
60
,
)
logger
.
debug
(
"
Got response to %s
"
,
method
)
break
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
synapse/util/async.py
+
20
−
0
View file @
0e6b3e4e
...
...
@@ -32,3 +32,23 @@ def run_on_reactor():
iteration of the main loop
"""
return
sleep
(
0
)
def
time_bound_deferred
(
given_deferred
,
clock
,
time_out
):
ret_deferred
=
defer
.
Deferred
()
def
timed_out
():
if
not
given_deferred
.
called
:
given_deferred
.
cancel
()
ret_deferred
.
errback
(
RuntimeError
(
"
Timed out
"
))
timer
=
clock
.
call_later
(
time_out
,
timed_out
)
def
succeed
(
result
):
clock
.
cancel_call_later
(
timer
)
ret_deferred
.
callback
(
result
)
given_deferred
.
addCallback
(
succeed
)
given_deferred
.
addErrback
(
ret_deferred
.
errback
)
return
ret_deferred
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