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
5bc69040
Commit
5bc69040
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Plain Diff
Merge pull request #340 from matrix-org/erikj/server_retries
Retry dead servers a lot less often
parents
347146be
eacb068a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/http/matrixfederationclient.py
+8
-2
8 additions, 2 deletions
synapse/http/matrixfederationclient.py
synapse/util/retryutils.py
+5
-2
5 additions, 2 deletions
synapse/util/retryutils.py
with
13 additions
and
4 deletions
synapse/http/matrixfederationclient.py
+
8
−
2
View file @
5bc69040
...
@@ -35,6 +35,7 @@ from signedjson.sign import sign_json
...
@@ -35,6 +35,7 @@ from signedjson.sign import sign_json
import
simplejson
as
json
import
simplejson
as
json
import
logging
import
logging
import
random
import
sys
import
sys
import
urllib
import
urllib
import
urlparse
import
urlparse
...
@@ -55,6 +56,9 @@ incoming_responses_counter = metrics.register_counter(
...
@@ -55,6 +56,9 @@ incoming_responses_counter = metrics.register_counter(
)
)
MAX_RETRIES
=
4
class
MatrixFederationEndpointFactory
(
object
):
class
MatrixFederationEndpointFactory
(
object
):
def
__init__
(
self
,
hs
):
def
__init__
(
self
,
hs
):
self
.
tls_server_context_factory
=
hs
.
tls_server_context_factory
self
.
tls_server_context_factory
=
hs
.
tls_server_context_factory
...
@@ -119,7 +123,7 @@ class MatrixFederationHttpClient(object):
...
@@ -119,7 +123,7 @@ class MatrixFederationHttpClient(object):
# XXX: Would be much nicer to retry only at the transaction-layer
# XXX: Would be much nicer to retry only at the transaction-layer
# (once we have reliable transactions in place)
# (once we have reliable transactions in place)
retries_left
=
5
retries_left
=
MAX_RETRIES
http_url_bytes
=
urlparse
.
urlunparse
(
http_url_bytes
=
urlparse
.
urlunparse
(
(
""
,
""
,
path_bytes
,
param_bytes
,
query_bytes
,
""
)
(
""
,
""
,
path_bytes
,
param_bytes
,
query_bytes
,
""
)
...
@@ -180,7 +184,9 @@ class MatrixFederationHttpClient(object):
...
@@ -180,7 +184,9 @@ class MatrixFederationHttpClient(object):
)
)
if
retries_left
and
not
timeout
:
if
retries_left
and
not
timeout
:
yield
sleep
(
2
**
(
5
-
retries_left
))
delay
=
5
**
(
MAX_RETRIES
+
1
-
retries_left
)
delay
*=
random
.
uniform
(
0.8
,
1.4
)
yield
sleep
(
delay
)
retries_left
-=
1
retries_left
-=
1
else
:
else
:
raise
raise
...
...
This diff is collapsed.
Click to expand it.
synapse/util/retryutils.py
+
5
−
2
View file @
5bc69040
...
@@ -18,6 +18,7 @@ from twisted.internet import defer
...
@@ -18,6 +18,7 @@ from twisted.internet import defer
from
synapse.api.errors
import
CodeMessageException
from
synapse.api.errors
import
CodeMessageException
import
logging
import
logging
import
random
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -85,8 +86,9 @@ def get_retry_limiter(destination, clock, store, **kwargs):
...
@@ -85,8 +86,9 @@ def get_retry_limiter(destination, clock, store, **kwargs):
class
RetryDestinationLimiter
(
object
):
class
RetryDestinationLimiter
(
object
):
def
__init__
(
self
,
destination
,
clock
,
store
,
retry_interval
,
def
__init__
(
self
,
destination
,
clock
,
store
,
retry_interval
,
min_retry_interval
=
5000
,
max_retry_interval
=
60
*
60
*
1000
,
min_retry_interval
=
10
*
60
*
1000
,
multiplier_retry_interval
=
2
,):
max_retry_interval
=
24
*
60
*
60
*
1000
,
multiplier_retry_interval
=
5
,):
"""
Marks the destination as
"
down
"
if an exception is thrown in the
"""
Marks the destination as
"
down
"
if an exception is thrown in the
context, except for CodeMessageException with code < 500.
context, except for CodeMessageException with code < 500.
...
@@ -140,6 +142,7 @@ class RetryDestinationLimiter(object):
...
@@ -140,6 +142,7 @@ class RetryDestinationLimiter(object):
# We couldn't connect.
# We couldn't connect.
if
self
.
retry_interval
:
if
self
.
retry_interval
:
self
.
retry_interval
*=
self
.
multiplier_retry_interval
self
.
retry_interval
*=
self
.
multiplier_retry_interval
self
.
retry_interval
*=
int
(
random
.
uniform
(
0.8
,
1.4
))
if
self
.
retry_interval
>=
self
.
max_retry_interval
:
if
self
.
retry_interval
>=
self
.
max_retry_interval
:
self
.
retry_interval
=
self
.
max_retry_interval
self
.
retry_interval
=
self
.
max_retry_interval
...
...
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