Commit 28292df8 authored by ibuler's avatar ibuler

[Update] 增加异常捕捉

parent b5c5f65e
...@@ -105,7 +105,10 @@ class Coco: ...@@ -105,7 +105,10 @@ class Coco:
def keep_heartbeat(self): def keep_heartbeat(self):
def func(): def func():
while not self.stop_evt.is_set(): while not self.stop_evt.is_set():
self.heartbeat() try:
self.heartbeat()
except Exception as e:
logger.error("Unexpected error occur: {}".format(e))
time.sleep(config["HEARTBEAT_INTERVAL"]) time.sleep(config["HEARTBEAT_INTERVAL"])
thread = threading.Thread(target=func) thread = threading.Thread(target=func)
thread.start() thread.start()
...@@ -151,17 +154,20 @@ class Coco: ...@@ -151,17 +154,20 @@ class Coco:
def func(): def func():
while not self.stop_evt.is_set(): while not self.stop_evt.is_set():
sessions_copy = [s for s in Session.sessions.values()] try:
for s in sessions_copy: sessions_copy = [s for s in Session.sessions.values()]
# Session 没有正常关闭, for s in sessions_copy:
if s.closed_unexpected: # Session 没有正常关闭,
Session.remove_session(s.id) if s.closed_unexpected:
continue Session.remove_session(s.id)
# Session已正常关闭 continue
if s.closed: # Session已正常关闭
Session.remove_session(s) if s.closed:
else: Session.remove_session(s)
check_session_idle_too_long(s) else:
check_session_idle_too_long(s)
except Exception as e:
logger.error("Unexpected error occur: {}".format(e))
time.sleep(interval) time.sleep(interval)
thread = threading.Thread(target=func) thread = threading.Thread(target=func)
thread.start() thread.start()
......
...@@ -103,7 +103,10 @@ class ProxyNamespace(BaseNamespace): ...@@ -103,7 +103,10 @@ class ProxyNamespace(BaseNamespace):
forwarder = ProxyServer(client, asset, system_user) forwarder = ProxyServer(client, asset, system_user)
def proxy(): def proxy():
forwarder.proxy() try:
forwarder.proxy()
except Exception as e:
logger.error("Unexpected error occur: {}".format(e))
self.logout(client_id, connection) self.logout(client_id, connection)
self.socketio.start_background_task(proxy) self.socketio.start_background_task(proxy)
......
...@@ -110,7 +110,10 @@ class SSHServer: ...@@ -110,7 +110,10 @@ class SSHServer:
kind = client.request.kind kind = client.request.kind
if kind == 'session' and chan_type in supported: if kind == 'session' and chan_type in supported:
logger.info("Request type `{}:{}`, dispatch to interactive mode".format(kind, chan_type)) logger.info("Request type `{}:{}`, dispatch to interactive mode".format(kind, chan_type))
InteractiveServer(client).interact() try:
InteractiveServer(client).interact()
except Exception as e:
logger.error("Unexpected error occur: {}".format(e))
connection = Connection.get_connection(client.connection_id) connection = Connection.get_connection(client.connection_id)
connection.remove_client(client.id) connection.remove_client(client.id)
elif chan_type == 'subsystem': elif chan_type == 'subsystem':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment