mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Disconnect handlers if the client closes a connection.
Tested using the following procedure (run-dev.py won't pass through the client connect closing) tabbott@monastery:~/zulip$ curl http://localhost:9991/api/v1/register -u email:key -d 'event_types=["message"]' {"msg":"","max_message_id":2259,"last_event_id":-1,"result":"success","queue_id":"1386884005:0"} tabbott@monastery:~/zulip$ curl -G http://localhost:9993/api/v1/events -u email:key -d "last_event_id=0" -d "queue_id=1386884005:0" (then hit ctrl-C) (imported from commit 3c4f3d5caac97b3de53da994ff9cd9ef67b2b9ea)
This commit is contained in:
@@ -127,6 +127,7 @@ class ClientDescriptor(object):
|
||||
|
||||
def connect_handler(self, handler):
|
||||
self.current_handler = handler
|
||||
handler.client_descriptor = self
|
||||
self.last_connection_time = time.time()
|
||||
def timeout_callback():
|
||||
self._timeout_handle = None
|
||||
@@ -137,7 +138,13 @@ class ClientDescriptor(object):
|
||||
if self.client_type.name != 'API: heartbeat test':
|
||||
self._timeout_handle = ioloop.add_timeout(heartbeat_time, timeout_callback)
|
||||
|
||||
def disconnect_handler(self):
|
||||
def disconnect_handler(self, client_closed=False):
|
||||
if self.current_handler:
|
||||
self.current_handler.client_descriptor = None
|
||||
if client_closed:
|
||||
request = self.current_handler._request
|
||||
logging.info("Client disconnected for queue %s (%s via %s)" % \
|
||||
(self.event_queue.id, request._email, request.client.name))
|
||||
self.current_handler = None
|
||||
if self._timeout_handle is not None:
|
||||
ioloop = tornado.ioloop.IOLoop.instance()
|
||||
|
||||
Reference in New Issue
Block a user