Skip to content

fix(proxy): drain and start fresh instead of hot-restarting across an Envoy worker-count change (#1136) - #1147

Merged
bpalermo merged 5 commits into
mainfrom
fix/1136-fresh-start-on-concurrency-change
Oct 3, 2026
Merged

bpalermo merged 5 commits into
mainfrom
fix/1136-fresh-start-on-concurrency-change

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Closes #1136

Problem

#1133 stopped a hot restart across a worker-count change from crashing the successor. It still resets about half of the parent's live QUIC connections. The child attaches its connection-ID steering program (SO_ATTACH_REUSEPORT_CBPF, CID % concurrency) to the sockets it inherits, and that program belongs to the whole reuse-port group:

  • 4→2: the parent's datagrams are steered mod 2, so connections with CID % 4 ∈ {2,3} reach a parent worker that does not own them. You see Mismatched worker index. expected 3, actual 1, then a stateless reset. On talos-main on 2026-10-02 this was 34 lines and 12 resets fleet-wide.
  • 2→4: the child's new sockets for workers 2–3 are not paused, so they take about half of the parent's connections.

Change

Only a cross-pod start can see a different count. An in-pod hot restart forks with the supervisor's own ExtraArgs, which never change for its lifetime. So the check sits where initStartEpoch confirms a live predecessor. That point also covers a bind-collision retry.

  1. Read the parent's count. On one admin connection, read /server_info → command_line_options.concurrency. The predecessor is another supervisor's Envoy, so its answer cannot carry our identity. It is trusted only if it is LIVE, at the heartbeat's epoch, and carries an aether supervisor's --admin-address-path identity (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). Anything else hot-restarts exactly as before: unreachable, unparsable, no identity (a non-aether or 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 Envoy), another epoch, or no concurrency reported. The check never blocks a normal roll.
  2. Work out the successor's count. Use --concurrency from the envoy args (Envoy keeps the last one). If the flag is absent (the chart default, proxy.concurrency: 0), use the node's online CPU count from /sys/devices/system/cpu/online. That is what Envoy's default hardware_concurrency() returns. If it can't be read, hot-restart.
  3. Equal counts: hot restart, unchanged, counted as mode=hot.
  4. Different counts:
    • Log one WARN naming both counts (envoy worker count changes across this handoff; NOT hot-restarting …) and count mode=fresh_after_drain.
    • Send POST /drain_listeners?graceful on the connection that was just checked, then wait --drain-time.
    • Re-read the identity and epoch on a new connection, and send POST /quitquitquit on that same connection. The other pod's Envoy is in another PID namespace, so it cannot be signalled. Its supervisor sees exit 0 and takes its existing path: newest epoch terminated cleanly by successor; awaiting pod deletion.
    • Wait until the admin no longer answers as the predecessor (bounded), wait 1 s, then start epoch 0 of a new lineage. The predecessor is never drained twice, even if its stop failed.
  5. Readiness: once a fresh lineage replaces a drained predecessor, adminServerInfo counts an answer as LIVE only if it carries our identity. Otherwise a predecessor still answering at epoch 0 could make the new pod Ready before its own Envoy is up. In every other case readiness is decided exactly as before.
  6. Opt-out: supervisor flag --hot-restart-on-concurrency-change (default off, meaning fresh start), chart value proxy.hotRestart.hotRestartOnConcurrencyChange: false. With it on, a mismatch is logged at WARN and hot-restarted.
  7. Metric: aether.supervisor.handoff_mode{mode=hot|fresh_after_drain}, seeded at 0.

The predecessor drain does not use admin_mutations (#1127's "only owner=own is sent" counter). It is a deliberate request to the verified predecessor, and both requests ride a connection whose identity was checked.

Tests

hotrestart/concurrencychange_test.go, with a fake admin that reports concurrency and implements /quitquitquit:

case assertion
(a) counts equal hot restart at E+1, gate armed, no drain/stop
(b) parent 4 / successor 2 drain on the checked connection ([/server_info, /drain_listeners]), stop on a re-checked connection ([/server_info, /quitquitquit]), nextEpoch=0, ungated, own-identity readiness
(c) parent 2 / successor 4 same as (b)
no --concurrency the online CPU count decides (equal → hot, differs → fresh, unknown → hot)
(d) no identity / non-aether identity / no concurrency hot restart, predecessor untouched
another epoch / not LIVE readPredecessor rejects it
opt-out flag hot restart across a change
already-drained predecessor never drained twice
fresh-lineage readiness a foreign Envoy LIVE at epoch 0 is not Ready; our own is
metrics handoff_mode seeded at 0 per mode

Red runs. With freshStartInsteadOfHotRestart returning false and the identity rule off (main's behaviour), (b), (c), "default differs" and the readiness test fail. With the trust checks removed (a naive implementation), all three (d) subcases fail. (a) and the inconclusive cases pin behaviour main already has, so they cannot be red against main.

Commands run:

  • bazel test //agent/internal/proxy/hotrestart/... //agent/internal/supervisorcmd/... //agent/cmd/proxy-supervisor/...: green, including deps_test (stdlib only).
  • bazel test --config=race on hotrestart, supervisorcmd and deps_test: green.
  • bazel test //charts/...: green, including the new aether_proxy_hot_restart_on_concurrency_change_test.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...: green.

Kind leg (red → green): e2e/proxy-concurrency-change.sh

Setup:

  • Cluster aether-1136, two nodes. Sources on the control plane, destinations on the worker, so every request crosses an east-west QUIC twin between two node proxies.
  • Load: 16 curl loops (client-a/b → quic-a/b, 4 each) for 180 s.
  • 15 s into the load, helm upgrade changes only proxy.concurrency, so only the proxy DaemonSet rolls.
  • Every proxy pod's log is snapshotted each second and counted from the upgrade on.
  • Images are identical in both runs except the supervisor: red is main, green is this branch.
run supervisor Mismatched worker index handoffs requests non-200 ≥1 s max latency
4→2 main 14 2 hot 96,722 5 × 503 0 –
4→2 (repeat) main 14 2 hot 95,292 10 × 503 0 0.18 s
2→4 main 0 (index in range, see #1133) 2 hot 101,746 10 × 503 0 0.17 s
4→2 branch 0 2 fresh_after_drain 91,476 0 n/a n/a
4→2 (repeat) branch 0 2 fresh_after_drain 103,220 0 32 2.13 s
2→4 branch 0 2 fresh_after_drain 92,967 0 32 2.13 s

A same-count rollout restart on the branch image took live predecessor confirmed; starting cross-pod hot restart on both nodes, so the default path is unchanged.

Drain-window cost, measured. On each node:

  • the drain took 11.0 s (--drain-time 10 s, plus the stop and 1 s settle);
  • the fresh Envoy started 1 ms after predecessor drained and was LIVE and Ready 1.0 s later.

The node had no listeners for about 2 s. Each of the 16 loops had exactly one request that waited it out on SYN retransmits (16 per node, max 2.13 s), and none failed. The previous pod's supervisor logged newest epoch terminated cleanly by successor; awaiting pod deletion and then pod not ready.

Docs

  • charts/aether/values.yaml: the proxy.concurrency comment and the new proxy.hotRestart.hotRestartOnConcurrencyChange.
  • docs/configuration.md: both rows.
  • runbook § Sizing nodes for a proxy hot restart: a count change is now a drain + fresh start, with the mechanism, the metric, the cost and the e2e.
  • Chart 2.2.3 → 2.2.4.

Risks

Do not merge before tonight's soak has started.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 5 commits October 2, 2026 20:02
… Envoy worker-count change (#1136)

A hot restart between different --concurrency values re-steers the parent's
QUIC connections by the child's count: the child attaches its connection-ID
steering program (SO_ATTACH_REUSEPORT_CBPF, CID % concurrency) to the sockets
it inherits, and the program belongs to the whole reuse-port group. On 4 -> 2
about half of the parent's live HTTP/3 connections land on a parent worker that
does not own them (Mismatched worker index, stateless reset); on 2 -> 4 the
child's new, unpaused sockets for workers 2-3 take about half of them.

When initStartEpoch confirms a live predecessor, the supervisor now reads its
/server_info (command_line_options.concurrency) and compares it with the count
its own Envoy will run (--concurrency in the envoy args, else the online CPU
count, Envoy's default). The answer is trusted only when it is LIVE, at the
heartbeat's epoch and carries an aether supervisor's admin identity (#1127);
anything else hot-restarts as before. On a mismatch it logs one WARN naming
both counts, drains the predecessor gracefully on the connection that was
checked, waits --drain-time, stops it with /quitquitquit after re-checking its
identity on that connection, waits for its admin to go, and starts a fresh
lineage at epoch 0. Readiness in the new lineage requires an answer carrying
our own identity, so a predecessor still answering at epoch 0 cannot make the
pod Ready. New counter aether.supervisor.handoff_mode{mode=hot|fresh_after_drain},
seeded at 0. --hot-restart-on-concurrency-change (chart:
proxy.hotRestart.hotRestartOnConcurrencyChange) forces the old hot restart.

Kind leg e2e/proxy-concurrency-change.sh (two nodes, 16 h3 curl loops):
main 4->2: 14 Mismatched worker index lines, 5-10 x 503 per roll; 2->4: 10 x
503. Branch: 0 Mismatched, 0 failed requests in both directions; the fresh
start costs a ~2 s no-listener gap per node (max request latency 2.13 s).

Chart 2.2.3 -> 2.2.4.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 197f1cc into main Oct 3, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1136-fresh-start-on-concurrency-change branch October 3, 2026 02:28
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