summary refs log tree commit diff
path: root/synapse/rest/client/transactions.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2017-02-13 13:33:12 +0000
committerKegan Dougal <kegan@matrix.org>2017-02-13 13:33:12 +0000
commitfeb15dc99f02e6cb0a84a53e397529c51743f114 (patch)
treed3ad7af04b1f07bbe12a8f157d02dde9e0223f7c /synapse/rest/client/transactions.py
parenthttp txns: Do not cache error responses (diff)
downloadsynapse-feb15dc99f02e6cb0a84a53e397529c51743f114.tar.xz
Don't cache errors at all
Diffstat (limited to 'synapse/rest/client/transactions.py')
-rw-r--r--synapse/rest/client/transactions.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/synapse/rest/client/transactions.py b/synapse/rest/client/transactions.py
index 6396a08035..95376a2fb6 100644
--- a/synapse/rest/client/transactions.py
+++ b/synapse/rest/client/transactions.py
@@ -81,16 +81,7 @@ class HttpTransactionCache(object):
             Deferred which resolves to a tuple of (response_code, response_dict).
         """
         try:
-            observable = self.transactions[txn_key][0]
-            if not observable.has_called() or observable.has_succeeded():
-                return observable.observe()
-            # if the request has already been called with a non-2xx status
-            # (a Twisted failure), remove it from the transaction map.
-            # This is done to ensure that we don't cache rate-limiting errors, etc.
-            res = observable.get_result()
-            if res.value.code >= 300:
-                del self.transactions[txn_key]
-                # fall through
+            return self.transactions[txn_key][0].observe()
         except (KeyError, IndexError):
             pass  # execute the function instead.
 
@@ -101,6 +92,14 @@ class HttpTransactionCache(object):
         # to the observers.
         observable = ObservableDeferred(deferred, consumeErrors=True)
         self.transactions[txn_key] = (observable, self.clock.time_msec())
+
+        # if the request fails with a Twisted failure, remove it
+        # from the transaction map. This is done to ensure that we don't
+        # cache transient errors like rate-limiting errors, etc.
+        def remove_from_map(err):
+            del self.transactions[txn_key]
+            return err
+        observable.addErrback(remove_from_map)
         return observable.observe()
 
     def _cleanup(self):