[wasm][ai-proxy] 高频配置更新下,AI 路由出现按请求比例的静默 fail-open 404(upstream path 前缀丢失),伴随 #3920 的 VM 泄漏指纹 || Silent per-request fail-open 404s on AI routes under frequent config updates, with the VM leak signature of #3920
TL;DR (English)
On a production AI gateway (Higress 2.2.4, 3 replicas, 20 workers + main thread, 10 Wasm filters per listener), an external scheduler adjusts AI-route upstream weights via the Console REST API every 30s–5min (1% granularity). Each adjustment triggers a full config push including WasmPlugin ECDS pushes.
After accumulating days of such churn, gateway pods begin silently failing open on ~3.9% of AI-route requests per request, uniformly distributed: the ai-proxy filter is skipped, the provider path prefix (openaiCustomUrl, e.g. /sglang-router/v1) is not prepended, and the upstream replies 404 within ~5ms. response_code_details: via_upstream, response_flags: "-". Restarting the pod clears it completely — new pods stay clean under the same push storm.
Fresh pods show wasm.envoy.wasm.runtime.v8.created ≫ expected (245/248 vs 210) and active above the expected per-thread VM count (217/219 vs 210) within 2.5–4 hours — the same signature as #3920. The fail-open path itself is completely silent (Debug-level log only, no counter), so the problem is invisible until end users report 404s.
环境
- Higress gateway / controller / console:v2.2.4(ACK 集群,gateway 3 副本,concurrency=20)
- ai-proxy:官方 OCI 镜像
plugins/ai-proxy:2.0.0;ai-proxy.internal实例由 AI 路由产品功能自动管理(45 个 provider、55 条 matchRules,failStrategy: FAIL_OPEN) - 每个 listener 挂 10 个 Wasm filter,预期 VM 数 = 10 插件 × 21 线程(20 worker + main)= 210
- 流量约 1200 万请求/天;外部容量调度系统通过 Console API 以 30s–5min 间隔对 AI 路由做 1% 粒度权重自动调整
现象(两起事故,间隔 5 天,特征完全一致)
第一起(单 Pod)与第二起(两 Pod)关键数据(第二起,时间窗约 10 分钟):
| Pod(重启前运行 5.5 天) | 200 | 404(命中正常路由) | 失败率 |
|---|---|---|---|
| pod A | 7,030 | 287 | ≈3.9% |
| pod B | 6,415 | 262 | ≈3.9% |
| pod C | — | 0 | 0% |
- 404 按秒均匀散布(每秒 1–9 个,无簇状爆发),失败率 ≈ N 个 worker 中坏 1 个的比例
- consumer / user-agent / 客户端 IP / 路由 / 上游 endpoint 各维度均与流量成比例,无任何请求特征能区分成败
- ~02:46Z 起 3 个 Pod 相继出现 readiness 探针超时(
15021/healthz/ready context deadline exceeded),人工滚动重启后 404 归零,此时调权推送风暴仍在持续
失败请求 access log 指纹(脱敏):
{"method":"POST","path":"/v1/chat/completions","response_code":"404","response_flags":"-",
"response_code_details":"via_upstream","route_name":"ai-route-foo.internal",
"upstream_cluster":"outbound|80||llm-provider-a.internal.dns","upstream_service_time":"5",
"bytes_sent":"0","duration":"19",
"ai_log":"{\"api\":\"-\",\"chat_round\":1,\"consumer\":\"consumerA\"}",
"user_agent":"OpenAI/Python 2.0.0"}即:路由命中正确、上游秒拒 5ms、ai_log 缺 model 字段 → ai-proxy 的 provider path 前缀未生效(正常请求 path 为 /sglang-router/v1/chat/completions)。
证据
1. 与 Pod 年龄强相关(运行时坏状态,非配置问题)
- 3 个同配置、同 RS 的 Pod,仅运行 5.5 天的两个出问题;重启后新 Pod 在同一推送风暴下 404=0
- 事故期间 WasmPlugin 配置版本未变(
version_text全程停在02:35:46Z/2120)
2. WASM VM 泄漏指纹(与 #3920 一致)
重启后数小时的新 Pod 实测(推送风暴持续中):
pod1(运行 3h51m):v8.created: 245 / v8.active: 217
pod2(运行 2h36m):v8.created: 248 / v8.active: 219
预期:210(10 插件 × 21 线程)
pod1 rebuild 计数:ai-proxy.internal 19(explicit 17 + memory 2)
model-mapper.internal 11
model-router.internal 2
ai-statistics 1 → 合计 33 ≈ created − 210- 数小时内多创建 35–38 个 VM,与 rebuild 总数吻合 → 每次配置触发重建都在换 VM
active比预期多 7–9 且不回落 → 每次重建有相当比例旧 VM 未释放,与 #3920 描述的active远高于预期一致
3. 重建churn 与推送频率正相关
- controller 日志:调权风暴期间每 1–5 分钟一次
WasmPlugin: PUSH ... 10 configs, 57.2kB(30 个 ingress 聚合);调权事件从事故前基线 ~3.6 分钟/次飙至 30 秒/次 - 事故 Pod 的 ai-proxy ECDS 计数:
update_attempt 570 / update_failure 269(47%)/ update_success 300;新 Pod 同期 15–23/5–8(新 Pod 也有 ~35% 失败,故 update_failure 本身是常态噪音,但老 Pod 显著更高) - 实测权重采样(连续 3 分钟):
58/12/30/0 → 57/13/30/0 → 56/15/29/0——每分钟 1% 粒度真实变更
4. fail-open 完全静默(可观测性为零)
plugins/wasm-go/extensions/ai-proxy/main.go 中 4 个入口(request headers/body、response headers/body)的跳过分支均为:
if activeProvider == nil {
log.Debugf("[onHttpRequestHeader] no active provider, skip processing") // 生产级别不可见
ctx.DontReadRequestBody()
return types.ActionContinue // 静默放行
}结合 WasmPlugin 的 failStrategy: FAIL_OPEN:VM 重建/配置未就绪窗口内,个别 worker 上的请求被无日志、无计数地放行——这正是两起事故"无指标、无日志、用户报障才发现"的直接原因。
根因假设
高频(分钟级)AI 路由权重变更 → 每次全量推送含 WasmPlugin ECDS → wasm filter 反复重建(换 VM): ① 重建窗口内部分 worker 上插件配置未初始化 → FAIL_OPEN 静默放行 → path 前缀丢失 → 上游 404(按请求均匀分布,与"21 worker 坏 1 个 ≈ 4.8%"的观测吻合); ② 每次重建有比例地泄漏旧 VM →
v8.active膨胀 + 内存增长(#3920)。 老 Pod 累计数百次重建后劣化到 ~3.9% 失败率 + 探针超时,重启清零。
与现有 issue / PR 的关系
- #3920(Envoy 内存持续增长):我们在新 Pod 上复现了同样的
v8.active膨胀指纹,并补充了"重建由配置推送触发"的量化链路 - #3923(移除 request-count 重建触发器,v2.2.3):方向正确,但我们的 rebuild 以
rebuild_explicit(配置触发)为主——配置推送驱动的重建churn 仍在,且官方插件 OCI 镜像(如ai-proxy:2.0.0)与网关版本的同步机制(#4022)导致插件侧修复难以自动到位 - #3419(key-auth 运行一段时间后偶发失效,
Unable to create Wasm HTTP filter,重启恢复):疑似同族问题(重建/配置下发竞态导致的 per-worker 失效),我们的场景是无任何报错的静默版
期望
- 可观测性:wasm-go wrapper / ai-proxy 的 fail-open 分支增加计数器指标(如
fail_open_total,带 plugin/route 维度)与非 Debug 级日志(含 route/host/path)。这是所有同类问题排查的前提 - 竞态窗口:排查 ECDS 触发的 VM 重建期间 per-worker "配置未就绪 → 直接 fail-open" 的窗口;考虑初始化完成前排队/快速等待,或至少让 fail-open 可计量、可告警
- 推送去抖:controller 对 WasmPlugin 配置做内容哈希比对,内容未变时不重复 PUSH(我们观测到 version_text 不变期间 update_attempt 持续攀升);调权类高频变更是否可避免触发 wasm filter 重建值得评估
- 文档/默认值:AI 路由场景建议在文档中提示为
proxy-next-upstream配置http_404(映射retriable-status-codes: [404])作为此类静默 fail-open 的止损手段
复现思路
- 3 副本、concurrency=20、加载含 ai-proxy(providers 使用
openaiCustomUrl路径前缀)在内的 ~10 个 Wasm 插件 - 循环通过 Console REST API 每 30–60s 修改某 AI 路由上游权重 ±1%,持续数小时~数天
- 观察:
rebuild_total与v8.created持续增长、created − 销毁差值扩大;累计重建较多的 Pod 上出现按请求 ~4% 的缺前缀 404;重启清除
我们的临时缓解
- 滚动重启劣化 Pod(立即恢复)
- 为事故路由追加
http_404重试条件,让 fail-open 请求自动重试到健康 worker - 计划:按
v8.active超阈值告警精准重启;推动调度系统做变更阈值抑制以降低推送频率
补充说明:受监控粒度限制(rebuild_total 仅 main_thread 粒度、fail-open 无计数),per-worker 坏状态暂无法直接证实,以上为证据支撑的最优假设,欢迎维护者指教。
Source: higress-group/higress