Skip to content

fix(supervisor): send the self-drain only to this supervisor's own Envoy, never to another proxy pod's Envoy on the shared admin address (#1127) - #1134

Merged
bpalermo merged 1 commit into
mainfrom
fix/1127-supervisor-admin-identity
Oct 2, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/1127-supervisor-admin-identity

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Closes #1127

Mechanism, confirmed from code and reproduced on kind

The supervisor makes one state-changing admin request: POST /drain_listeners?graceful in drainThenShutdown, the drain_fallback branch. It does not call healthcheck/fail or quitquitquit; it stops Envoy with signals (terminateChildren, stopWedged). Every other admin call is a read (/server_info, /ready).

On main the drain is sent blind to cfg.AdminAddress (127.0.0.1:9901). It runs when the successor wait expires, from both the successor_wait and the mid-handoff arm, or straight away with --shutdown-drain-immediately. Nothing checks that our Envoy still owns the admin, or that our Envoy is still alive.

A hot-restart child asks its parent to shut down the parent's admin and then binds the admin itself. If that child crashes (#1126), the old Envoy keeps serving with no admin. The new pod's supervisor then starts a fresh epoch-0 Envoy, which binds 9901. When the old supervisor's wait expires (155 s at chart defaults), its drain reaches the new pod's Envoy. That Envoy then adds no listeners for any pod created afterwards.

The kind leg below reproduced this exactly on the main supervisor.

Fix: a per-supervisor identity, verified on the connection that carries the drain

  • Every Envoy the supervisor forks gets --admin-address-path <ready-marker dir>/envoy-admin-address.<POD_NAME>.<96-bit random>. /server_info echoes the path as command_line_options.admin_address_path. Envoy's only other use of the flag is to write its admin address into that file; a failed write is logged and not fatal. The file lives in the pod-local ready-marker emptyDir because the root filesystem is read-only.
  • ownAdminRequest dials one TCP connection, sends GET /server_info, and sends the drain on the same connection only if the answer carries our nonce and an epoch whose child we still track. Envoy serves a connection from the process that accepted it, so there is no window between the check and the drain. The client is raw HTTP/1.1 (req.Write / http.ReadResponse) so a transport cannot silently redial.
  • When the check fails (foreign Envoy, admin unreachable, Connection: close after the check) or no child is tracked, nothing is sent. The supervisor logs one WARN with adminOwner, answeredBy=<pod>.<nonce>, answeredEpoch and ourEpoch, then continues the shutdown path: it waits out the drain window and SIGTERMs its own Envoy.
  • New counter aether.supervisor.admin_mutations{request=drain_listeners, owner=own|foreign|unreachable|own_envoy_gone}, seeded at zero.
  • supervisorcmd refuses an --envoy-arg that sets --admin-address-path (Envoy rejects the flag twice) and passes POD_NAME, which the chart already sets, into the identity for log labels.

Why not the alternatives

  • Epoch alone. A fresh Envoy of another pod is also epoch 0, which is the incident.
  • PID. Each pod has its own PID namespace; the incident's Envoys were pid 16 and 17 in different pods. /server_info does not report a PID either.
  • xDS node id (--service-node/--service-zone/--service-cluster). The agent keys configuration off these.
  • --base-id-path. Envoy throws if it cannot write the file.
  • --socket-path. It must match across pods for the cross-pod hot restart.
  • --stats-tag. It changes every stat.
  • A UDS admin in an emptyDir. Envoy has a single admin address, and the cross-pod protocol depends on the shared TCP admin (initStartEpoch, the handoff and ready-gate probes, and the e2e/operator curl 127.0.0.1:9901). Moving it would redesign the handoff.
  • Checking the nonce and then sending the drain on a new connection. This leaves a time-of-check/time-of-use window. One connection closes it.

Tests

Unit tests (hotrestart/adminidentity_test.go):

  • Foreign Envoy, no drain. Covers a foreign Envoy at the same epoch 0 (the incident shape), a foreign successor at a newer epoch, and --shutdown-drain-immediately with a foreign Envoy. All three were red on main (drainHits 1, expected 0).
  • Own Envoy gone, no drain. No drain even when the answer echoes our own nonce. Also red on main.
  • Own Envoy, drain sent on the checked connection. The fake admin records [/server_info, /drain_listeners] on one connection.
  • Other skip cases. Our nonce at an untracked epoch, Connection: close after the check (no second dial), and an unreachable admin all send nothing.
  • Plumbing. Carrier argv and per-supervisor uniqueness, cleanup of stale identity files, metric seeding, and the reserved --envoy-arg.
  • Changed existing test. TestHandleShutdownFallsBackToDrainWhenNoSuccessorComes used to assert that the drain is sent to an Envoy answering at a newer epoch. That Envoy is the successor's, so the assertion encoded the bug; it now asserts no drain and still checks the wait and the reap.

Commands run:

  • bazel test //agent/internal/proxy/hotrestart/... //agent/internal/supervisorcmd/... //agent/cmd/proxy-supervisor/...: green, including deps_test. scripts/check-proxy-supervisor-deps.sh reports OK. No new dependencies; stdlib only.
  • bazel test --config=race on hotrestart and supervisorcmd: green.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: green.

Kind leg: e2e/supervisor-admin-identity.sh. It uses the eastwest-quic bring-up on cluster aether-1127 with proxy.terminationGracePeriodSeconds=45, so the successor wait is 20 s. Steps:

  1. Roll the proxy so it runs at epoch 1.
  2. Roll again and SIGKILL the successor Envoy (epoch 2) once it owns the admin. This stands in for the proxy: Envoy segfaults in HotRestartingChild::onForwardedUdpPacket when the successor has fewer workers than the parent (4→2 hot restart, 'Mismatched worker index') #1126 crash.
  3. The new pod starts fresh at epoch 0 and the old pod goes into its successor wait.
  4. After the old pod is gone, replace the quic-a pod and assert that its inbound listener appears and that 20 requests from client-a return 200.
supervisor image old pod at the end of its wait new pod's listener requests
main (run twice) listeners drained; stopping envoy drainAccepted=true never added (listener_added stuck at 25) 20 x 000
this branch (run twice) not sending envoy admin request: ... ANOTHER envoy adminOwner=foreign answeredBy=envoy-admin-address.aether-proxy-vddxs.… answeredEpoch=0 ourEpoch=1, then drainAccepted=false present 20/20 x 200

The first branch run returned 503 for about 6 s while the replaced pod warmed up (its SVID was not yet served, and the first use builds its QUIC twin). Its listener was already present, and a manual request a few seconds later returned 200. The leg now waits up to SAI_WARMUP_S (60 s) for the first 200 before asserting the batch. The main-image failure happens before that wait, at the missing listener.

Risks

  • No graceful drain in this case. When the successor has already taken the old Envoy's admin and then died, the old pod cannot drain its own Envoy gracefully, because its admin is gone. It is SIGTERMed at the end of the wait instead. Before this change the drain hit someone else's Envoy, so this is strictly better, but connections still open on the old Envoy at that point are cut. admin_mutations{owner="foreign"} counts these.
  • Upgrade transition. Envoys started by a pre-supervisor: the old pod's self-drain calls the Envoy admin on 127.0.0.1:9901 without checking it is its own Envoy — it drained the NEW pod's freshly started Envoy, which then served no new listeners #1127 supervisor have no admin_address_path. During the first roll onto this version, the new supervisor treats such an Envoy as foreign: it never drains it, and it would not have owned it anyway. An old supervisor terminating during that roll still drains blind, once.
  • Identity files. One small file per supervisor process in the ready-marker emptyDir. Stale files from earlier container restarts are removed at startup.
  • No chart change and no Chart.yaml bump. The flag is added by the supervisor binary and POD_NAME is already in the proxy container's env.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…voy, never to another proxy pod's Envoy on the shared admin address (#1127)

Proxy pods are hostNetwork, so 127.0.0.1:9901 is one address for the whole
node. The only state-changing admin request the supervisor makes is the
drain_fallback POST /drain_listeners?graceful, and it went to whatever
answered. On 2026-10-01 the old pod's Envoy had handed its admin to a
successor that then crashed (#1126). The new pod's fresh epoch-0 Envoy bound
the port, the old supervisor's successor wait expired, and it drained that
Envoy. That Envoy then added no listeners for new pods until the next handoff.

Every forked Envoy now gets --admin-address-path set to a per-supervisor
nonce (<ready-marker dir>/envoy-admin-address.<pod>.<random>). /server_info
echoes it as command_line_options.admin_address_path. The drain is sent only
when /server_info returns that nonce AND an epoch whose child this supervisor
still tracks. The check and the drain go over the same TCP connection, so
there is no window in which the port can change hands. A foreign Envoy, an
unreachable admin, or an exited own Envoy means nothing is sent. The
supervisor logs one WARN naming whose Envoy answered, and the shutdown path
continues. New counter: aether.supervisor.admin_mutations{request,owner}.
--admin-address-path is now reserved: an --envoy-arg that sets it is refused.

Kind leg e2e/supervisor-admin-identity.sh, red on the main supervisor
(drainAccepted=true, the replaced pod's listener never added) and green on
this branch (foreign WARN, listener present, 20/20 x 200).

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

1 participant