Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
1330c311
Commit
1330c311
authored
5 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
make FederationClient._try_destination_list async
parent
a46fabf1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/federation/federation_client.py
+26
-10
26 additions, 10 deletions
synapse/federation/federation_client.py
with
26 additions
and
10 deletions
synapse/federation/federation_client.py
+
26
−
10
View file @
1330c311
...
@@ -17,7 +17,17 @@
...
@@ -17,7 +17,17 @@
import
copy
import
copy
import
itertools
import
itertools
import
logging
import
logging
from
typing
import
Any
,
Dict
,
Iterable
,
List
,
Optional
,
Tuple
from
typing
import
(
Any
,
Awaitable
,
Callable
,
Dict
,
Iterable
,
List
,
Optional
,
Tuple
,
TypeVar
,
)
from
prometheus_client
import
Counter
from
prometheus_client
import
Counter
...
@@ -53,6 +63,8 @@ sent_queries_counter = Counter("synapse_federation_client_sent_queries", "", ["t
...
@@ -53,6 +63,8 @@ sent_queries_counter = Counter("synapse_federation_client_sent_queries", "", ["t
PDU_RETRY_TIME_MS
=
1
*
60
*
1000
PDU_RETRY_TIME_MS
=
1
*
60
*
1000
T
=
TypeVar
(
"
T
"
)
class
InvalidResponseError
(
RuntimeError
):
class
InvalidResponseError
(
RuntimeError
):
"""
Helper for _try_destination_list: indicates that the server returned a response
"""
Helper for _try_destination_list: indicates that the server returned a response
...
@@ -349,17 +361,21 @@ class FederationClient(FederationBase):
...
@@ -349,17 +361,21 @@ class FederationClient(FederationBase):
return
signed_auth
return
signed_auth
@defer.inlineCallbacks
async
def
_try_destination_list
(
def
_try_destination_list
(
self
,
description
,
destinations
,
callback
):
self
,
description
:
str
,
destinations
:
Iterable
[
str
],
callback
:
Callable
[[
str
],
Awaitable
[
T
]],
)
->
T
:
"""
Try an operation on a series of servers, until it succeeds
"""
Try an operation on a series of servers, until it succeeds
Args:
Args:
description
(unicode)
: description of the operation we
'
re doing, for logging
description: description of the operation we
'
re doing, for logging
destinations
(Iterable[unicode])
: list of server_names to try
destinations: list of server_names to try
callback
(callable)
: Function to run for each server. Passed a single
callback: Function to run for each server. Passed a single
argument: the server_name to try.
May return a deferred.
argument: the server_name to try.
If the callback raises a CodeMessageException with a 300/400 code,
If the callback raises a CodeMessageException with a 300/400 code,
attempts to perform the operation stop immediately and the exception is
attempts to perform the operation stop immediately and the exception is
...
@@ -370,7 +386,7 @@ class FederationClient(FederationBase):
...
@@ -370,7 +386,7 @@ class FederationClient(FederationBase):
suppressed if the exception is an InvalidResponseError.
suppressed if the exception is an InvalidResponseError.
Returns:
Returns:
The
[Deferred]
result of callback, if it succeeds
The result of callback, if it succeeds
Raises:
Raises:
SynapseError if the chosen remote server returns a 300/400 code, or
SynapseError if the chosen remote server returns a 300/400 code, or
...
@@ -381,7 +397,7 @@ class FederationClient(FederationBase):
...
@@ -381,7 +397,7 @@ class FederationClient(FederationBase):
continue
continue
try
:
try
:
res
=
yield
callback
(
destination
)
res
=
await
callback
(
destination
)
return
res
return
res
except
InvalidResponseError
as
e
:
except
InvalidResponseError
as
e
:
logger
.
warning
(
"
Failed to %s via %s: %s
"
,
description
,
destination
,
e
)
logger
.
warning
(
"
Failed to %s via %s: %s
"
,
description
,
destination
,
e
)
...
@@ -400,7 +416,7 @@ class FederationClient(FederationBase):
...
@@ -400,7 +416,7 @@ class FederationClient(FederationBase):
)
)
except
Exception
:
except
Exception
:
logger
.
warning
(
logger
.
warning
(
"
Failed to %s via %s
"
,
description
,
destination
,
exc_info
=
1
"
Failed to %s via %s
"
,
description
,
destination
,
exc_info
=
True
)
)
raise
SynapseError
(
502
,
"
Failed to %s via any server
"
%
(
description
,))
raise
SynapseError
(
502
,
"
Failed to %s via any server
"
%
(
description
,))
...
...
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