From 9dc4997fccfae7ddc6b52d78d75aa115f2aa9134 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Mon, 6 Oct 2025 21:45:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E5=A4=84=E7=90=86=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=B6=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=20CancelledError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在异步任务被取消时,`session.close()` 操作可能会抛出 `asyncio.CancelledError`。 此提交通过捕获该特定异常并记录警告,增强了连接关闭过程的健壮性,防止了因未处理的异常而导致程序意外中断。 --- src/common/database/connection_pool_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/database/connection_pool_manager.py b/src/common/database/connection_pool_manager.py index 4ca789b6f..d0a68e8d4 100644 --- a/src/common/database/connection_pool_manager.py +++ b/src/common/database/connection_pool_manager.py @@ -55,6 +55,8 @@ class ConnectionInfo: try: await self.session.close() logger.debug("连接已关闭") + except asyncio.CancelledError: + logger.warning("关闭连接时任务被取消") except Exception as e: logger.warning(f"关闭连接时出错: {e}")