diff --git a/webssh/handler.py b/webssh/handler.py index 151e8b7..3a4a68f 100644 --- a/webssh/handler.py +++ b/webssh/handler.py @@ -462,15 +462,9 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler): worker.on_write() def on_close(self): - if self.close_reason: - logging.info( - 'Disconnecting to {}:{} with reason: {reason}'.format( - *self.src_addr, reason=self.close_reason - ) - ) - else: + logging.info('Disconnected from {}:{}'.format(*self.src_addr)) + if not self.close_reason: self.close_reason = 'client disconnected' - logging.info('Disconnected from {}:{}'.format(*self.src_addr)) worker = self.worker_ref() if self.worker_ref else None if worker: diff --git a/webssh/worker.py b/webssh/worker.py index 788240f..d90cec7 100644 --- a/webssh/worker.py +++ b/webssh/worker.py @@ -29,6 +29,7 @@ class Worker(object): self.data_to_dst = [] self.handler = None self.mode = IOLoop.READ + self.closed = False def __call__(self, fd, events): if events & IOLoop.READ: @@ -95,6 +96,10 @@ class Worker(object): self.update_handler(IOLoop.READ) def close(self, reason=None): + if self.closed: + return + self.closed = True + logging.info( 'Closing worker {} with reason: {}'.format(self.id, reason) )