From 74c304ae4030c51b4fab7777dd714f9e8a612da3 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 18 Nov 2013 11:29:45 -0500 Subject: [PATCH] Don't send heartbeat events to clients that don't request them. (imported from commit 1147814b22fb9737a807057ddbdbe0e9554086e0) --- zerver/lib/event_queue.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/zerver/lib/event_queue.py b/zerver/lib/event_queue.py index 7b5f641f5a..f3943732c0 100644 --- a/zerver/lib/event_queue.py +++ b/zerver/lib/event_queue.py @@ -98,13 +98,16 @@ class ClientDescriptor(object): def connect_handler(self, handler): self.current_handler = handler self.last_connection_time = time.time() - def timeout_callback(): - self._timeout_handle = None - # All clients get heartbeat events - self.add_event(dict(type='heartbeat')) - ioloop = tornado.ioloop.IOLoop.instance() - heartbeat_time = time.time() + HEARTBEAT_MIN_FREQ_SECS + random.randint(0, 10) - self._timeout_handle = ioloop.add_timeout(heartbeat_time, timeout_callback) + + if self.accepts_event_type('heartbeat'): + def timeout_callback(): + self._timeout_handle = None + # We already checked whether the client accepts heartbeats + self.add_event(dict(type='heartbeat')) + ioloop = tornado.ioloop.IOLoop.instance() + heartbeat_time = time.time() + HEARTBEAT_MIN_FREQ_SECS + random.randint(0, 10) + self._timeout_handle = ioloop.add_timeout(heartbeat_time, timeout_callback) + logging.info("DEBUG: connected handler for queue %s" % (self.event_queue.id,)) def disconnect_handler(self):