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) logger.info("TX [%s] Nothing to send", destination)
return 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 # Sort based on the order field
pending_pdus.sort(key=lambda t: t[2]) pending_pdus.sort(key=lambda t: t[2])
@ -194,7 +185,15 @@ class TransactionQueue(object):
self.store, 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 self.pending_transactions[destination] = 1
logger.debug("TX [%s] Persisting transaction...", destination) logger.debug("TX [%s] Persisting transaction...", destination)
@ -220,6 +219,7 @@ class TransactionQueue(object):
transaction.transaction_id, transaction.transaction_id,
) )
with limiter:
# Actually send the transaction # Actually send the transaction
# FIXME (erikj): This is a bit of a hack to make the Pdu age # 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 twisted.internet import defer
from synapse.api.errors import CodeMessageException
import logging import logging
@ -67,7 +69,7 @@ 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=20000, max_retry_interval=60 * 60 * 1000, min_retry_interval=20000, max_retry_interval=60 * 60 * 1000,
multiplier_retry_interval=2): multiplier_retry_interval=2,):
self.clock = clock self.clock = clock
self.store = store self.store = store
self.destination = destination self.destination = destination
@ -87,7 +89,11 @@ class RetryDestinationLimiter(object):
failure.value 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. # We connected successfully.
if not self.retry_interval: if not self.retry_interval:
return return