From b6b6b0310f62749a2c3885f6d878c6b0cba84971 Mon Sep 17 00:00:00 2001 From: Jad Date: Sun, 30 Mar 2025 12:58:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E9=80=80=E5=87=BA=E6=97=B6?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E4=BF=9D=E5=AD=98=E8=AE=B0=E5=BF=86=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=AB=8B=E5=8D=B3=E9=87=8D=E8=BF=9E=E6=97=B6=E9=98=BB?= =?UTF-8?q?=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index ff3c816a..373c977a 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -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):