From d46f446364100a6ae64dc91e3d1813dde37634ee Mon Sep 17 00:00:00 2001 From: NathanAlex7 <18898599977@163.com> Date: Tue, 1 Sep 2026 17:08:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(xingbang):=20=E9=87=8D=E8=AF=95=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E6=89=A9=E5=B1=95=E5=88=B0=E7=9E=AC=E6=97=B6=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E9=94=99=E8=AF=AF(502/=E8=BF=9E=E6=8E=A5=E4=B8=AD?= =?UTF-8?q?=E6=96=AD/chunked=20read)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 公司网关除 503 外还会抛 502 Bad Gateway / peer closed connection / incomplete chunked read 等瞬时错误。将所有这些纳入重试, 提升流水线对 不稳定网关的通过率。 --- backend/xingbang/agents.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/xingbang/agents.py b/backend/xingbang/agents.py index df17504..fd24f5e 100644 --- a/backend/xingbang/agents.py +++ b/backend/xingbang/agents.py @@ -126,13 +126,18 @@ class XingbangAgent: except Exception as e: # noqa last_err = e msg = str(e) - # 仅对 503/限流 重试 - if "503" in msg or "overloaded" in msg or "429" in msg: - if attempt < max_retries - 1: - await asyncio.sleep(backoff * (2 ** attempt)) - continue + # 对瞬时网络/网关错误重试: 503过载/502坏网关/429限流/连接中断/不完整响应 + retriable = any(k in msg for k in ( + "503", "502", "overloaded", "429", "rate", + "peer closed", "incomplete chunked", "Bad Gateway", + "timeout", "timed out", "Connection", "connection", + "ReadTimeout", "EOF", + )) + if retriable and attempt < max_retries - 1: + await asyncio.sleep(backoff * (2 ** attempt)) + continue else: - raise # 非限流错误立即失败 + raise # 非瞬时错误, 或重试耗尽 else: raise RuntimeError(f"网关过载重试后仍失败: {last_err}") # 保存产出到文件