fix: 修复自动重试的竞态条件问题
问题:delayed_retry_submit 闭包捕获的是旧的 account 对象 - 5秒后检查 should_stop 时,可能检查的是旧对象 - 如果账户被删除/重建,会导致状态检查不可靠 - 可能导致重复任务提交 修复: - 在 delayed_retry_submit 中重新调用 safe_get_account 获取最新账户对象 - 添加账户不存在的检查 - 添加取消时的日志输出,便于调试 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user