diff options
author | Erik Johnston <erik@matrix.org> | 2015-02-17 17:20:56 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-02-17 17:20:56 +0000 |
commit | 2b8f1a956c6a1d767a3b60e84e7d0afe5857fb0d (patch) | |
tree | ed4e08b47ac6c8a680ff5ba87b26077f70173776 /synapse/federation/federation_client.py | |
parent | Rate limit retries when fetching server keys. (diff) | |
download | synapse-2b8f1a956c6a1d767a3b60e84e7d0afe5857fb0d.tar.xz |
Add per server retry limiting.
Factor out the pre destination retry logic from TransactionQueue so it can be reused in both get_pdu and crypto.keyring
Diffstat (limited to 'synapse/federation/federation_client.py')
-rw-r--r-- | synapse/federation/federation_client.py | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 70c9a6f46b..c5b0274c2f 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -23,6 +23,8 @@ from synapse.api.errors import CodeMessageException from synapse.util.logutils import log_function from synapse.events import FrozenEvent +from synapse.util.retryutils import get_retry_limiter, NotRetryingDestination + import logging @@ -163,24 +165,34 @@ class FederationClient(FederationBase): pdu = None for destination in destinations: try: - transaction_data = yield self.transport_layer.get_event( - destination, event_id + limiter = yield get_retry_limiter( + destination, + self._clock, + self.store, ) - logger.debug("transaction_data %r", transaction_data) + with limiter: + transaction_data = yield self.transport_layer.get_event( + destination, event_id + ) - pdu_list = [ - self.event_from_pdu_json(p, outlier=outlier) - for p in transaction_data["pdus"] - ] + logger.debug("transaction_data %r", transaction_data) - if pdu_list: - pdu = pdu_list[0] + pdu_list = [ + self.event_from_pdu_json(p, outlier=outlier) + for p in transaction_data["pdus"] + ] - # Check signatures are correct. - pdu = yield self._check_sigs_and_hash(pdu) + if pdu_list: + pdu = pdu_list[0] - break + # Check signatures are correct. + pdu = yield self._check_sigs_and_hash(pdu) + + break + except NotRetryingDestination as e: + logger.info(e.message) + continue except CodeMessageException: raise except Exception as e: |