summary refs log tree commit diff
path: root/synapse/util/async_helpers.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-09-19 11:04:42 +0100
committerErik Johnston <erik@matrix.org>2018-09-19 11:07:27 +0100
commit6c48aa0256ce7dfd62e72a77b03f5bb2222473ba (patch)
tree7cae58d4b844c56c6876facf1970b9ace75cb513 /synapse/util/async_helpers.py
parentNewsfile (diff)
downloadsynapse-6c48aa0256ce7dfd62e72a77b03f5bb2222473ba.tar.xz
Run canceller first to allow it to generate correct error
Diffstat (limited to 'synapse/util/async_helpers.py')
-rw-r--r--synapse/util/async_helpers.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py
index 2e12bcda98..2b2e85ecb7 100644
--- a/synapse/util/async_helpers.py
+++ b/synapse/util/async_helpers.py
@@ -421,11 +421,14 @@ def timeout_deferred(deferred, timeout, reactor, on_timeout_cancel=None):
     def time_it_out():
         timed_out[0] = True
 
+        try:
+            deferred.cancel()
+        except:   # noqa: E722, if we throw any exception it'll break time outs
+            logger.exception("Canceller failed during timeout")
+
         if not new_d.called:
             new_d.errback(DeferredTimeoutError(timeout, "Deferred"))
 
-        deferred.cancel()
-
     delayed_call = reactor.callLater(timeout, time_it_out)
 
     def convert_cancelled(value):