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:16:48 +0000
committerKegan Dougal <kegan@matrix.org>2017-02-13 13:16:48 +0000
commitecd7e36047d090cdb027f500b0f95a375ba61811 (patch)
treea5b55467c076d5bb92cf71c896a10d731e440a86 /synapse/rest/client/transactions.py
parentMerge pull request #1912 from matrix-org/markjh/roominitialsync (diff)
downloadsynapse-ecd7e36047d090cdb027f500b0f95a375ba61811.tar.xz
http txns: Do not cache error responses
Previously we did. This meant that, amongst other errors, rate-limiting errors
would be cached and prevent messages with that txn ID being sent.
Diffstat (limited to 'synapse/rest/client/transactions.py')
-rw-r--r--synapse/rest/client/transactions.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/rest/client/transactions.py b/synapse/rest/client/transactions.py
index efa77b8c51..6396a08035 100644
--- a/synapse/rest/client/transactions.py
+++ b/synapse/rest/client/transactions.py
@@ -81,7 +81,16 @@ class HttpTransactionCache(object):
             Deferred which resolves to a tuple of (response_code, response_dict).
         """
         try:
-            return self.transactions[txn_key][0].observe()
+            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
         except (KeyError, IndexError):
             pass  # execute the function instead.