DEBUG.WIKI
野草云;香港 200Mbps 峰值;不限月流量 · BGP VPS;查看套餐 →
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 Envoy 报错 503 UC upstream_reset_before_response_started

分析 Envoy 与 Istio 代理在转发请求时触发 503 UC 响应重置的常见原因,提供 HTTP/2 降级、空闲连接超时与优雅关闭优化方案。

问题现象

客户端调用服务返回 503 Service Unavailable,查看 Envoy 访问日志中的响应标志(Response Flags)为 UC:

[2026-11-15T10:00:00.123Z] "POST /api/v1/trade HTTP/1.1" 503 UC upstream_reset_before_response_started - "-" 0 95 2 - "-" "curl/7.68.0" "..." "10.244.1.25:8080" outbound|8080||trade-service.default.svc.cluster.local - -

触发根因

  1. 上游后端服务(Upstream)主动向 Envoy 发送了 TCP RST(重置),例如后端服务因 OOM、崩溃退出或 Keep-Alive 超时关闭了连接。
  2. HTTP Keep-Alive 超时时间配置倒挂:后端业务服务的 keep-alive 超时时间小于 Envoy 的空闲超时时间(Idle Timeout),导致 Envoy 发送请求时后端刚好关闭连接。

解决步骤与操作命令

步骤一:排查后端 Pod 是否异常重启或崩溃

kubectl get pods -l app=trade-service
kubectl logs -l app=trade-service --previous

检查是否存在 OOMKilled 或 panic 迹象。

步骤二:调整连接保持超时(Keep-Alive Timeout)

确保后端业务服务器的 Keep-Alive 超时时间长于 Envoy 的连接空闲超时时间。例如后端设置为 65 秒,Envoy 设置为 60 秒:

若在 Istio 环境下,通过 DestinationRule 明确空闲超时:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: trade-service-pool
spec:
  host: trade-service.default.svc.cluster.local
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1024
      http:
        idleTimeout: 60s
        maxRequestsPerConnection: 100

步骤三:开启局部重试机制

在 VirtualService 中配置对于连接重置(connect-failure / reset)的安全重试:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: trade-service-retry
spec:
  hosts:
    - trade-service
  http:
    - route:
        - destination:
            host: trade-service
      retries:
        attempts: 3
        perTryTimeout: 2s
        retryOn: "connect-failure,refused-stream,reset"

验证确认

进行压力测试并验证 Envoy 统计指标:

kubectl exec -it <pod-name> -c istio-proxy -- pilot-agent request GET stats | grep upstream_rq_503

确认重试生效且外部不再透传 503 UC 异常。