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:
Tim Abbott
2013-12-12 13:47:24 -05:00
parent cc0ce6b437
commit b8579c6848
2 changed files with 13 additions and 1 deletions

View File

@@ -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()