From 77bfcbd52a4e04a0d54557e3c166d2c396f16ecc Mon Sep 17 00:00:00 2001
From: liuzheng712 <liuzheng712@gmail.com>
Date: Thu, 25 Jan 2018 11:57:29 +0800
Subject: [PATCH] feat: update

---
 coco/httpd.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/coco/httpd.py b/coco/httpd.py
index 4cdaa40..71f68b1 100644
--- a/coco/httpd.py
+++ b/coco/httpd.py
@@ -148,11 +148,16 @@ class SSHws(Namespace, BaseWebSocketHandler):
     def on_logout(self, connection):
         logger.debug("{} logout".format(connection))
         if connection:
-            self.clients[request.sid]["proxy"][connection].close()
-            del self.clients[request.sid]["proxy"][connection]
-            del self.clients[request.sid]["forwarder"][connection]
-            self.clients[request.sid]["client"][connection].close()
-            del self.clients[request.sid]["client"][connection]
+            if connection in self.clients[request.sid]["proxy"].keys():
+                proxy = self.clients[request.sid]["proxy"][connection]
+                del self.clients[request.sid]["proxy"][connection]
+                proxy.close()
+            if connection in self.clients[request.sid]["forwarder"].keys():
+                del self.clients[request.sid]["forwarder"][connection]
+            if connection in self.clients[request.sid]["client"].keys():
+                client = self.clients[request.sid]["client"][connection]
+                del self.clients[request.sid]["client"][connection]
+                client.close()
 
 
 class HttpServer:
-- 
2.18.0