From f52e3c4aa03e3a1bd72a60a01463d5ce994e4c46 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sun, 10 Oct 2010 19:51:50 +0100 Subject: [PATCH] add a check to ensure that the events loop doesn't continue indefinitely --- deluge/ui/web/json_api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 19a980027..c190f2804 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -382,16 +382,21 @@ class EventQueue(object): # Create a deferred to and check again in 100ms d = Deferred() - reactor.callLater(0.5, self._get_events, listener_id, d) + reactor.callLater(0.1, self._get_events, listener_id, 0, d) return d - def _get_events(self, listener_id, d): + def _get_events(self, listener_id, count, d): if listener_id in self.__queue: queue = self.__queue[listener_id] del self.__queue[listener_id] d.callback(queue) else: - reactor.callLater(0.1, self._get_events, listener_id, d) + # Prevent this loop going on indefinitely incase a client leaves + # the page or disconnects uncleanly. + if count >= 3000: + d.callback(None) + else: + reactor.callLater(0.1, self._get_events, listener_id, count + 1, d) def remove_listener(self, listener_id, event): """