Skip to content

fix(xds): a request delivered to a pod in teardown fails 503 within 1 s, while the pod's veth still exists, so the source retries it (#1103) - #1122

Merged
bpalermo merged 3 commits into
mainfrom
fix/1103-destination-fast-fail
Oct 1, 2026
Merged

bpalermo merged 3 commits into
mainfrom
fix/1103-destination-fast-fail

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1103

What was happening

In the 2026-10-01 TRIPLE, the five 504 UT requests went to svc-3 pods that were being torn down. The source agents were restarting (#1118), so the source proxies still selected those endpoints. Every request was delivered to the destination node proxy. The destination then spent 5 s connecting to the app and wrote its 503 UF into a pod network that no longer had a veth.

The 5 s did not come from the app. The app was already gone, and a connect to a closed loopback port is refused in microseconds. What blocked the connect was the pod's lo being DOWN:

  • containerd's StopPodSandbox stops the containers, then tears the network down through go-cni.
  • libcni.Remove DELs its networks in the order it holds them (containerd/go-cni cni.go:320). containerd registers cni.WithLoNetwork before cni.WithDefaultConf (internal/cri/server/service_linux.go).
  • So the loopback plugin's DEL runs first, and it does netlink.LinkSetDown(lo) (containernetworking/plugins plugins/main/loopback/loopback.go:154).
  • The pod's conflist DEL runs after that: aether first, then the primary CNI, which deletes the veth.
  • In between, the node proxy's inbound listener still accepts requests. The app_<pod>_<port> hop dials 127.0.0.1 through a DOWN loopback, and the SYN is dropped, not refused. Measured: with lo up, a connect to a closed port fails with ECONNREFUSED in 0.0 s. With lo down it times out.
  • The app cluster sets no connect_timeout, so Envoy uses its 5 s default (source/common/upstream/upstream_impl.cc:1310).

The same sequence shows up in the destination access logs for every pod. Read-only VictoriaLogs on talos-main, reporter:destination upstream_cluster:app:

pod app gone: 503 UF Connection refused lo DOWN: 503 UF {connection_timeout} 5.00 s aether CNI DEL (listeners removed) veth gone (first Write failed … Network is unreachable)
jcfxj (w05) 05:41:23.29, 23.47 (9 ms, 62 ms) 23.93, 24.04 (stream lost at 3.0 s) 24.24–24.27 26.52
zv6zw (w02) 05:41:39.20, 39.26, 39.50 39.79, 39.92, 39.97 40.36–40.45 42.79

These are the five TRIPLE failures, and the source never heard either answer. Over 7 days there are 45 app-cluster connection_timeouts: 09-26, 09-27, 09-30 ×2 (the 09-30 soak's 6), and 10-01. Each one comes a few hundred ms after that pod's first fast refusals. The fast refusals (191 in 7 days) did reach their sources, which retried them; nobody saw those.

The kind repro shows why the veth outlives aether's DEL by about 2 s. aether's DEL waits up to readyProbeDelTimeout (2 s) for the pod's listener to refuse a probe. With lo DOWN no probe can be refused, so the DEL always runs out that budget before the primary CNI removes the veth. talos shows the same gap: 2.25 s and 2.43 s after the listener removal.

The fix

NewAppCluster now sets connect_timeout: 1s (meshconst.AppConnectTimeout). This applies to every app cluster, TCP or UDS. The health probe cluster inherits it; its HC timeout was already 1 s.

  • A request that arrives in the window fails 503 UF 1 s later. That is inside the ~2 s DEL hold, so the answer leaves the pod.
    • For the five TRIPLE requests: 24.93/25.04 against a veth that lived until ~26.5, and 40.79–40.97 against ~42.8.
  • The source retries it. outboundRetryPolicy (agent/internal/xds/proxy/route.go:65-82) has retriable-status-codes [503], previous_hosts, and 2 retries. Envoy maps a connect-timeout reset to 503 (source/common/router/router.cc:1739-1741, flag UF at :1805-1808). The source retries a 503 regardless of method (source/common/router/retry_state_impl.cc:385-391). The twin path uses the same route; the matcher only swaps the cluster.
    • The fast 503s also feed the source's consecutive_5xx: 5 outlier detection (agent/internal/xds/proxy/egress.go:541), which ejects the dying host and closes its connections.
  • Never replayed. UF {connection_timeout} means the TCP connect to the app never completed, so no request byte reached the app. That is why retrying a POST is safe here.
  • Steady state. A loopback connect is answered in microseconds while lo is up, whether it is accepted or refused. The only connect this bound can cut is an app whose listen backlog is full (the kernel drops the SYN, and the first retransmit is at 1 s). That request now gets a retriable 503 at 1 s instead of maybe getting through at 1–3 s.
  • In-flight requests and feat(agent): two-phase drain — DRAINING first, pool-close after delay #152. Untouched. connect_timeout applies only to new upstream connections. During preStop the app is alive and lo is up.

Why not the other options

  • (i) Have the agent switch the inbound to a local 503 on the drain mark. The app is alive and serving through preStop, so this would fail requests it can serve. The agent also never learns when lo goes down: that is containerd's loopback DEL, which runs before aether's. Only the connect bound covers the window.
  • (ii) Make CNI DEL wait. It already waits ~2 s in this state (above). A longer wait does not help a request whose 503 comes 5 s after it arrived.
  • (iii) A short timeout only while the pod is terminating. This needs an app-cluster rebuild at the drain mark. The window exists on every teardown, and a live loopback never comes near 1 s. More moving parts for no added safety.

Proof

Unit tests (red first):

  • TestNewAppCluster_ConnectTimeoutIsTheTeardownBound (TCP and pipe) failed on main with "unset means Envoy's 5 s default".
  • TestWaitGoneHoldsTheDelPastTheAppConnectTimeout pins the CNI side of the margin: a netns that never answers holds waitGone for the full readyProbeDelTimeout, and readyProbeDelTimeout >= 2*AppConnectTimeout.

kind (e2e/destination-teardown.sh, cluster aether-1103b):

  • Setup: EWQ_WORKER=1 shape, quic-a ×2 (agnhost) on the worker, no preStop, client-a on the control plane.
  • Per run:
    1. Freeze the source agent (SIGSTOP).
    2. Start 6 GET loops plus a POST every 0.5 s, unpinned.
    3. Stop the victim's app, set its lo DOWN (the loopback-DEL step), and delete the pod.
    4. The real CNI DEL follows.
  • The app-then-lo order is compressed on purpose. On an otherwise idle kind cluster, the source would eject the pod on the fast refusals before containerd's own loopback DEL (~0.3 s later). Unforced, both arms were clean: main 4 runs, this PR 2. On talos the sources had too few refusals each to eject.
arm (3 runs each) requests/run non-200 > 2.5 s max dying-pod app connect timeouts ids at more than one app
main (5b7cc7d) 915 / 827 / 844 6 / 10 / 9 (503 after 2.4–9.45 s) 6 / 10 / 8 9.45 s +5 / +2 / +4 (at 5 s) 0
this PR 1257 / 1236 / 1271 0 / 0 / 0 0 1.03 s +6 / +7 / +6 (at 1 s) 0 (every 200 at exactly one app)
  • Destination timeline, from the proxy debug log and a 20 ms in-netns sampler:
    • main: connects at 42.32–42.60, connect timeout at 47.32–47.60, then Write failed … Network is unreachable. The veth was gone at ~45.5. This is the talos signature.
    • branch: connects at 28.55–29.09, connect timeout and :status 503 encoded at 29.54–30.09. The veth was gone at 31.2. The clients got 200 in 0.95–1.03 s.
  • Unforced teardowns (preStop 3 s and 0 s) on the branch: 1269 and 1264 requests, all 200, max 49 ms.

Checks:

  • bazel test //agent/... //cni/... //common/constants/... //test/envoy_validate:all: 55/55 pass.
  • --config=race on //agent/internal/xds/proxy:all, //cni/internal/plugin:all, //common/constants/mesh:all, //test/envoy_validate:all: pass.
  • make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... (shellcheck covers the new harness): clean.
  • No chart change.

Risks

  • Agent rollout. On upgrade, every node's app_* clusters are re-pushed once with the new field. A STATIC cluster update keeps in-flight requests on the old cluster's connections and opens new ones for new requests. This is the standard Envoy cluster-update behaviour; I did not measure it under load during the agent swaps here.
  • An app that accepts slowly under load (full backlog) now gets 503 UF at 1 s, which the source retries elsewhere, instead of waiting up to 5 s. Watch cluster.app.upstream_cx_connect_timeout (node-aggregate, alt_stat_name: app) outside pod deletions.
  • CRI-O was not checked. The bound assumes a runtime that runs loopback DEL before the pod conflist DEL, as containerd (talos, kind) does. A runtime that leaves lo up refuses instantly and needs nothing.

Not covered (not part of the TRIPLE failures)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

… s, while the pod's veth still exists, so the source retries it (#1103)

containerd tears a pod's network down through go-cni, which DELs the
built-in loopback network (lo DOWN) before the pod's conflist (aether,
then the primary CNI, which removes the veth). In between, the node
proxy's inbound still accepts requests a stale source sends, and the
app_<pod>_<port> hop dials 127.0.0.1 through a DOWN loopback: the SYN
is dropped, not refused. With Envoy's default 5 s connect_timeout the
503 UF was written after the veth was gone (ENETUNREACH), and the
source waited for its own liveness timer. That is the whole 2026-10-01
TRIPLE signature (5 x 504) and the 2026-09-30 one (6).

Bound the app connect at meshconst.AppConnectTimeout (1 s). A live app
answers a loopback connect in microseconds; aether's CNI DEL holds ~2 s
in this state (its listener-gone probe cannot be refused with lo DOWN),
so the 503, which never reached the app, leaves the pod and the source
retries it on another endpoint (retriable 503, previous_hosts).

e2e/destination-teardown.sh reproduces it on kind with the source agent
frozen: main 6/10/9 failed requests per run (max 9.4 s), this change 0
(max 1.03 s), no request id at more than one app.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eds: a source proxy still picks an endpoint 3.4–3.8 s after the destination agent marked it DRAINING (the requests behind #1087's 504s)

1 participant