fix(server): 退出时等待保存记忆导致立即重连时阻塞

This commit is contained in:
Jad
2025-03-30 12:58:27 +08:00
parent 4c91bffcc7
commit b6b6b0310f
+10
View File
@@ -181,13 +181,23 @@ class ConnectionHandler:
except AuthenticationError as e:
self.logger.bind(tag=TAG).error(f"Authentication failed: {str(e)}")
await self.close(ws)
return
except Exception as e:
stack_trace = traceback.format_exc()
self.logger.bind(tag=TAG).error(f"Connection error: {str(e)}-{stack_trace}")
await self.close(ws)
return
finally:
self._save_and_close(ws)
async def _save_and_close(self, ws):
"""保存记忆并关闭连接"""
try:
await self.memory.save_memory(self.dialogue.dialogue)
except Exception as e:
self.logger.bind(tag=TAG).error(f"保存记忆失败: {e}")
finally:
await self.close(ws)
async def _route_message(self, message):