fix(db): 处理关闭连接时可能出现的 CancelledError

在异步任务被取消时,`session.close()` 操作可能会抛出 `asyncio.CancelledError`。

此提交通过捕获该特定异常并记录警告,增强了连接关闭过程的健壮性,防止了因未处理的异常而导致程序意外中断。
This commit is contained in:
tt-P607
2025-10-06 21:45:50 +08:00
parent 514b681ace
commit 3104414c79

View File

@@ -55,6 +55,8 @@ class ConnectionInfo:
try: try:
await self.session.close() await self.session.close()
logger.debug("连接已关闭") logger.debug("连接已关闭")
except asyncio.CancelledError:
logger.warning("关闭连接时任务被取消")
except Exception as e: except Exception as e:
logger.warning(f"关闭连接时出错: {e}") logger.warning(f"关闭连接时出错: {e}")