diff options
author | Erik Johnston <erik@matrix.org> | 2016-12-09 16:30:29 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-12-09 16:30:29 +0000 |
commit | fbaf868f621c2ecb6ea10679eb435f9adffa3b2a (patch) | |
tree | ddd0c34d774583c2234c8c669e845d379fb4b0f1 /synapse/notifier.py | |
parent | Fix rare notifier bug where listeners dont timeout (diff) | |
download | synapse-fbaf868f621c2ecb6ea10679eb435f9adffa3b2a.tar.xz |
Correctly handle timeout errors
Diffstat (limited to 'synapse/notifier.py')
-rw-r--r-- | synapse/notifier.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/synapse/notifier.py b/synapse/notifier.py index 40baa6969a..acbd4bb5ae 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -17,6 +17,7 @@ from twisted.internet import defer from synapse.api.constants import EventTypes, Membership from synapse.api.errors import AuthError +from synapse.util import DeferredTimedOutError from synapse.util.logutils import log_function from synapse.util.async import ObservableDeferred from synapse.util.logcontext import PreserveLoggingContext, preserve_fn @@ -320,6 +321,8 @@ class Notifier(object): listener.deferred, time_out=(end_time - now) / 1000. ) + except DeferredTimedOutError: + break except defer.CancelledError: break else: @@ -490,22 +493,27 @@ class Notifier(object): """ listener = _NotificationListener(None) - def timed_out(): - listener.deferred.cancel() + end_time = self.clock.time_msec() + timeout - timer = self.clock.call_later(timeout / 1000., timed_out) while True: listener.deferred = self.replication_deferred.observe() result = yield callback() if result: break + now = self.clock.time_msec() + if end_time <= now: + break + try: with PreserveLoggingContext(): - yield listener.deferred + yield self.clock.time_bound_deferred( + listener.deferred, + time_out=(end_time - now) / 1000. + ) + except DeferredTimedOutError: + break except defer.CancelledError: break - self.clock.cancel_call_later(timer, ignore_errs=True) - defer.returnValue(result) |