From e65485cb1ea15bcc526ebcc382a8ff2790104a4a Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Fri, 16 Jan 2026 22:32:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E7=9A=84=E7=AB=9E=E6=80=81=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:delayed_retry_submit 闭包捕获的是旧的 account 对象 - 5秒后检查 should_stop 时,可能检查的是旧对象 - 如果账户被删除/重建,会导致状态检查不可靠 - 可能导致重复任务提交 修复: - 在 delayed_retry_submit 中重新调用 safe_get_account 获取最新账户对象 - 添加账户不存在的检查 - 添加取消时的日志输出,便于调试 Co-Authored-By: Claude Opus 4.5 --- services/tasks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/tasks.py b/services/tasks.py index 12c138a..74ad36f 100644 --- a/services/tasks.py +++ b/services/tasks.py @@ -895,7 +895,13 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m _emit("account_update", account.to_dict(), room=f"user_{user_id}") def delayed_retry_submit(): - if account.should_stop: + # 重新获取最新的账户对象,避免使用闭包中的旧对象 + fresh_account = safe_get_account(user_id, account_id) + if not fresh_account: + log_to_client("自动重试取消: 账户不存在", user_id, account_id) + return + if fresh_account.should_stop: + log_to_client("自动重试取消: 任务已被停止", user_id, account_id) return log_to_client(f"🔄 开始第 {retry_count + 1} 次自动重试...", user_id, account_id) ok, msg = submit_account_task(