summary refs log tree commit diff
path: root/synapse/util/retryutils.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-03-23 00:12:21 +0000
committerRichard van der Hoff <richard@matrix.org>2017-03-23 09:28:46 +0000
commit4bd597d9fcb8e6c6888ee3e8fa683ba812272997 (patch)
tree14560ff81374c7d41d1ed24af3f3f47e46f5373c /synapse/util/retryutils.py
parentMatrixFederationHttpClient: clean up (diff)
downloadsynapse-4bd597d9fcb8e6c6888ee3e8fa683ba812272997.tar.xz
push federation retry limiter down to matrixfederationclient
rather than having to instrument everywhere we make a federation call,
make the MatrixFederationHttpClient manage the retry limiter.
Diffstat (limited to '')
-rw-r--r--synapse/util/retryutils.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/synapse/util/retryutils.py b/synapse/util/retryutils.py
index 153ef001ad..7e5a952584 100644
--- a/synapse/util/retryutils.py
+++ b/synapse/util/retryutils.py
@@ -124,7 +124,13 @@ class RetryDestinationLimiter(object):
 
     def __exit__(self, exc_type, exc_val, exc_tb):
         valid_err_code = False
-        if exc_type is not None and issubclass(exc_type, CodeMessageException):
+        if exc_type is None:
+            valid_err_code = True
+        elif not issubclass(exc_type, Exception):
+            # avoid treating exceptions which don't derive from Exception as
+            # failures; this is mostly so as not to catch defer._DefGen.
+            valid_err_code = True
+        elif issubclass(exc_type, CodeMessageException):
             # Some error codes are perfectly fine for some APIs, whereas other
             # APIs may expect to never received e.g. a 404. It's important to
             # handle 404 as some remote servers will return a 404 when the HS
@@ -142,11 +148,13 @@ class RetryDestinationLimiter(object):
             else:
                 valid_err_code = False
 
-        if exc_type is None or valid_err_code:
+        if valid_err_code:
             # We connected successfully.
             if not self.retry_interval:
                 return
 
+            logger.debug("Connection to %s was successful; clearing backoff",
+                         self.destination)
             retry_last_ts = 0
             self.retry_interval = 0
         else:
@@ -160,6 +168,10 @@ class RetryDestinationLimiter(object):
             else:
                 self.retry_interval = self.min_retry_interval
 
+            logger.debug(
+                "Connection to %s was unsuccessful (%s(%s)); backoff now %i",
+                self.destination, exc_type, exc_val, self.retry_interval
+            )
             retry_last_ts = int(self.clock.time_msec())
 
         @defer.inlineCallbacks