Try to only back off if we think we failed to connect to the remote

This commit is contained in:
Erik Johnston 2015-02-17 18:13:34 +00:00
parent c8436b38a0
commit 9371019133
3 changed files with 96 additions and 90 deletions

View File

@ -167,15 +167,6 @@ class TransactionQueue(object):
logger.info("TX [%s] Nothing to send", destination)
return
logger.debug(
"TX [%s] Attempting new transaction"
" (pdus: %d, edus: %d, failures: %d)",
destination,
len(pending_pdus),
len(pending_edus),
len(pending_failures)
)
# Sort based on the order field
pending_pdus.sort(key=lambda t: t[2])
@ -194,7 +185,15 @@ class TransactionQueue(object):
self.store,
)
with limiter:
logger.debug(
"TX [%s] Attempting new transaction"
" (pdus: %d, edus: %d, failures: %d)",
destination,
len(pending_pdus),
len(pending_edus),
len(pending_failures)
)
self.pending_transactions[destination] = 1
logger.debug("TX [%s] Persisting transaction...", destination)
@ -220,6 +219,7 @@ class TransactionQueue(object):
transaction.transaction_id,
)
with limiter:
# Actually send the transaction
# FIXME (erikj): This is a bit of a hack to make the Pdu age

View File

@ -15,6 +15,8 @@
from twisted.internet import defer
from synapse.api.errors import CodeMessageException
import logging
@ -67,7 +69,7 @@ def get_retry_limiter(destination, clock, store, **kwargs):
class RetryDestinationLimiter(object):
def __init__(self, destination, clock, store, retry_interval,
min_retry_interval=20000, max_retry_interval=60 * 60 * 1000,
multiplier_retry_interval=2):
multiplier_retry_interval=2,):
self.clock = clock
self.store = store
self.destination = destination
@ -87,7 +89,11 @@ class RetryDestinationLimiter(object):
failure.value
)
if exc_type is None and exc_val is None and exc_tb is None:
valid_err_code = False
if exc_type is CodeMessageException:
valid_err_code = 0 <= exc_val.code < 500
if exc_type is None or valid_err_code:
# We connected successfully.
if not self.retry_interval:
return