fix(xingbang): 重试范围扩展到瞬时网络错误(502/连接中断/chunked read)
公司网关除 503 外还会抛 502 Bad Gateway / peer closed connection / incomplete chunked read 等瞬时错误。将所有这些纳入重试, 提升流水线对 不稳定网关的通过率。
This commit is contained in:
@@ -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}")
|
||||
# 保存产出到文件
|
||||
|
||||
Reference in New Issue
Block a user