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():
try:
self.heartbeat() 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,6 +154,7 @@ class Coco: ...@@ -151,6 +154,7 @@ class Coco:
def func(): def func():
while not self.stop_evt.is_set(): while not self.stop_evt.is_set():
try:
sessions_copy = [s for s in Session.sessions.values()] sessions_copy = [s for s in Session.sessions.values()]
for s in sessions_copy: for s in sessions_copy:
# Session 没有正常关闭, # Session 没有正常关闭,
...@@ -162,6 +166,8 @@ class Coco: ...@@ -162,6 +166,8 @@ class Coco:
Session.remove_session(s) Session.remove_session(s)
else: else:
check_session_idle_too_long(s) 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():
try:
forwarder.proxy() 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))
try:
InteractiveServer(client).interact() 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