Repository navigation
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
Conversation
… 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
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1103
What was happening
In the 2026-10-01 TRIPLE, the five
504 UTrequests 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 its503 UFinto 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
lobeing DOWN:StopPodSandboxstops the containers, then tears the network down through go-cni.libcni.RemoveDELs its networks in the order it holds them (containerd/go-cnicni.go:320). containerd registerscni.WithLoNetworkbeforecni.WithDefaultConf(internal/cri/server/service_linux.go).netlink.LinkSetDown(lo)(containernetworking/pluginsplugins/main/loopback/loopback.go:154).app_<pod>_<port>hop dials127.0.0.1through a DOWN loopback, and the SYN is dropped, not refused. Measured: withloup, a connect to a closed port fails withECONNREFUSEDin 0.0 s. Withlodown it times out.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:503 UF Connection refused503 UF {connection_timeout}5.00 sWrite failed … Network is unreachable)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. WithloDOWN 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
NewAppClusternow setsconnect_timeout: 1s(meshconst.AppConnectTimeout). This applies to every app cluster, TCP or UDS. The health probe cluster inherits it; its HCtimeoutwas already 1 s.503 UF1 s later. That is inside the ~2 s DEL hold, so the answer leaves the pod.outboundRetryPolicy(agent/internal/xds/proxy/route.go:65-82) hasretriable-status-codes [503],previous_hosts, and 2 retries. Envoy maps a connect-timeout reset to503(source/common/router/router.cc:1739-1741, flagUFat: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.consecutive_5xx: 5outlier detection (agent/internal/xds/proxy/egress.go:541), which ejects the dying host and closes its connections.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.lois 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.connect_timeoutapplies only to new upstream connections. During preStop the app is alive andlois up.Why not the other options
logoes down: that is containerd's loopback DEL, which runs before aether's. Only the connect bound covers the window.Proof
Unit tests (red first):
TestNewAppCluster_ConnectTimeoutIsTheTeardownBound(TCP and pipe) failed on main with "unset means Envoy's 5 s default".TestWaitGoneHoldsTheDelPastTheAppConnectTimeoutpins the CNI side of the margin: a netns that never answers holdswaitGonefor the fullreadyProbeDelTimeout, andreadyProbeDelTimeout >= 2*AppConnectTimeout.kind (
e2e/destination-teardown.sh, clusteraether-1103b):EWQ_WORKER=1shape, quic-a ×2 (agnhost) on the worker, no preStop,client-aon the control plane.loDOWN (the loopback-DEL step), and delete the pod.connect timeoutat 47.32–47.60, thenWrite failed … Network is unreachable. The veth was gone at ~45.5. This is the talos signature.connect timeoutand:status 503encoded at 29.54–30.09. The veth was gone at 31.2. The clients got 200 in 0.95–1.03 s.Checks:
bazel test //agent/... //cni/... //common/constants/... //test/envoy_validate:all: 55/55 pass.--config=raceon//agent/internal/xds/proxy:all,//cni/internal/plugin:all,//common/constants/mesh:all,//test/envoy_validate:all: pass.make gazelle,make format, andbazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...(shellcheck covers the new harness): clean.Risks
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.503 UFat 1 s, which the source retries elsewhere, instead of waiting up to 5 s. Watchcluster.app.upstream_cx_connect_timeout(node-aggregate,alt_stat_name: app) outside pod deletions.loup refuses instantly and needs nothing.Not covered (not part of the TRIPLE failures)
loDOWN preceded the app exit by 1 s (the earlierINJECT_LO_DOWNvariant). With the real order, the fast 503s eject the host first.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr