You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
proxy-supervisor: shutdown admin probe runs on the already-cancelled ctx, so SIGTERM may never drain Envoy (needs reproduction) #771
Found by the 2026-09-15 codebase review (static race/lock review of agent/internal/proxy/hotrestart). Status: hypothesis with strong code evidence, not yet reproduced. Reproduce before fixing.
Claim: hotrestart/supervisor.go:372 — handleShutdown has exactly one call site, case <-lp.ctx.Done(), so by the time it runs the admin liveness probe it is issued on an already-cancelled context. The probe therefore always fails, !adminLiveAtEpoch is always true, and every SIGTERM takes the "wait for the successor to take over" branch and blocks in awaitProtocolTermination, which has no deadline despite the comment at :365 saying it does. Consequence if true: on pod delete / drain / evict / scale-down (any termination that is not a hot-restart handoff), Envoy is never told to drain; the pod sits until terminationGracePeriodSeconds and is SIGKILLed with connections open. Rolling restarts do not show this because they go through the successor path — which is why every hitless-rollout validation and soak has been green.
Reproduction plan (do this first, on talos-main during a quiet window, it is cheap):
Unit: a test that drives handleShutdown with the loop's ctx already cancelled and asserts which branch it takes and how long awaitProtocolTermination blocks (fake admin endpoint that reports live).
Cluster: kubectl delete pod one aether-proxy-* pod (NOT a rollout restart) while the prober runs; measure (a) pod termination duration vs terminationGracePeriodSeconds, (b) envoy_server_state / drain counters on that node before the pod goes, (c) prober error deltas on that node in the window, (d) the supervisor's INFO lines (which branch it logged). A termination that takes the full grace period with no drain log is the confirmation; a fast termination with a drain log refutes the claim and this issue closes.
Fix if confirmed (same PR, then a hitless-rollout validation + a delete-pod validation):
Probe with a fresh, short-deadline ctx (context.WithTimeout(context.Background(), …)) — the idiom already used elsewhere in the supervisor for admin calls.
Give awaitProtocolTermination the deadline its comment promises, falling back to an explicit drain + exit.
While in the file, review the four epoch-bookkeeping findings from the same report (epoch-key reuse clobbering a draining child; nextEpoch bumped before cmd.Start(); readyGate published after nextEpoch; epoch −1 clearing the ready marker during retries — the last is a candidate mechanism for the still-open 09-03 readiness-marker flap on w01/w05) and the fixed tmp-file name without fsync for the executable copy.
Reproduction result: mechanism CONFIRMED, predicted consequence REFUTED for kubectl delete pod
Run 2026-09-15 on talos-main (rev213, quiet cluster), repo HEAD 3c8f9c7. Nothing was fixed or modified; the unit test lives in a scratch snapshot.
Confirmed
One call site, and it is ctx.Done().supervisor.go:289-290 — case <-lp.ctx.Done(): return lp.s.handleShutdown(lp.ctx). lp.ctx is cmd.Context() → ctrl.SetupSignalHandler(), cancelled on SIGTERM.
The probe runs on the dead ctx and never reaches the network.adminprobe.go:271 does context.WithTimeout(ctx, readyPollInterval) on an already-cancelled parent. Unit test, production-shaped supervisor with a fake admin answering state:LIVE, restart_epoch:0 (our own epoch, explicitly not mid-handoff): sanity probe on a healthy ctx → live=true; 5 probes on the cancelled ctx → live=false in 4.8µs–48µs, with the fake admin's request and accepted-connection counters unchanged.
On-cluster proof of the same thing. Over each deleted pod's 2d21h life, aether_supervisor_admin_probes_total{aether_supervisor_probe_endpoint="server_info"} recorded result="unreachable"exactly once — at its SIGTERM (w03: 1 at the 22:07:00 scrape; w05: 1 at 22:08:30), while result="live" was climbing +10/30s right up to that scrape (41,720 / 41,744) and envoy_server_state{node=…} was 0 (LIVE) at every step. The other server_info call sites did not run in that window.
The branch is taken unconditionally. Both deletes logged hotrestart/supervisor.go:373 "termination requested mid-handoff; waiting for successor to terminate our envoy"194ms / 195ms after the delete — while Envoy was LIVE at our own epoch and the replacement Envoy would not start for another 4.3–6.3s.
awaitProtocolTermination has no deadline and no ctx (:742-753, bare <-s.childExited). Unit test: still blocked at 3.0s, child still tracked and never signalled (no SIGTERM, no drain, drainCompleted never recorded); it returned only when the child was killed externally.
Note the comment conflict is real but inverted from how the issue frames it: :364-365 promises "a deadline fallback", while the function's own comment at :735-741 says it "deliberately imposes NO deadline" and explains why (killing the parent early aborts the successor with errno 111). :364-365 is the stale one.
Controls that isolate the cause: same supervisor + same LIVE fake admin but a non-cancelled ctx → drain branch in 30ms, real probe, child SIGTERMed and reaped. And with a live ctx but admin LIVE at epoch 1 (a genuine handoff) → correctly blocks. So the branch logic is sound; the context it is selected with is the bug.
Refuted — what actually happens on kubectl delete pod
Two samples, kubectl delete pod (not a rollout restart), log follower started before the delete, 1 Hz pod-JSON poller to retain the terminated state. terminationGracePeriodSeconds: 180.
main-worker-03 dk4b4
main-worker-05 ltl7q
:373 mid-handoff line
+0.194s
+0.195s
old Envoy "terminating parent process"
+6.485s
+4.467s
old Envoy "closing and draining listeners"
+7.238s
+5.333s
"caught ENVOY_SIGTERM" (parent-shutdown-time 15s)
+22.18s
+20.27s
supervisor "envoy epoch terminated by successor"
+22.41s
+20.54s
wall clock, delete → object gone
23.372s
21.439s
terminated state
exitCode=0 reason=Completed (both containers)
exitCode=0 reason=Completed (both containers)
Not the grace period (23s/21s vs 180s), not 137, and Envoy was drained.
Why: the aether-proxy DaemonSet creates the replacement pod on the same node within ~1s of the deletionTimestamp, and that pod's Envoy performs a genuine cross-pod hot restart (shared --base-id=0), becoming the successor that protocol-terminates the parent. A kubectl delete pod self-rescues into exactly the surge-roll path — the same reason every hitless-rollout validation and soak has been green.
Data-plane cost: zero
sum by (node,tier,target,result) (aether_probe_requests_total{result!="success"}) over 22:04:00–22:11:00Z, fleet-wide, returns one series: a pre-existing prober-mgf4w / mesh_dns / *.svc.cluster.local / timeout = 1, flat at 1 at every step and already present in the pre-delete baseline. Successes climbed linearly through both windows (+300/30s per tier, both targets, both nodes). 0 new liveness errors, 0 new dns_*, 0 new http_error, 0 new timeouts. All 5 proxies back to 2/2 Ready (replacements Ready at +93s and +33s).
Falsifiable prediction from the report
aether_supervisor_drain_duration*does not exist as a metric name in Prometheus at all, while its sibling aether_supervisor_handoff_duration_seconds_* from the same meter does — consistent with s.shutdown() never completing in production. Caveat: a process SIGKILLed at the grace period would not flush its final export either, so absence alone is not conclusive; the log evidence above is what settles it.
Residual exposure — why this should still be fixed
The branch is now unconditional, so correctness on every termination depends entirely on a successor appearing. Where one cannot appear — graceful node shutdown, node deletion/scale-down, kubectl delete daemonset or a chart uninstall, or a replacement stuck Pending/ImagePullBackOff/unschedulable — awaitProtocolTermination blocks with no deadline until SIGKILL at 180s, with no drain and connections open. That case is reproduced in the unit test; it is not reproducible with pod deletes alone on this DaemonSet, so I did not induce it on-cluster (it would have required editing shared config).
Fix ordering matters: do not just add a deadline — :735-741 explains why there isn't one. Fix the ctx first so the branch is entered only when genuinely mid-handoff (the repo already has the idiom, added for #662: common/telemetry/setup/lifecycle.go:23DetachedTimeout = context.WithTimeout(context.WithoutCancel(parent), d)), and only then add a bounded no-successor fallback.
Grading a fix against this baseline
On kubectl delete pod of an aether-proxy, a correct fix must: log :377 "termination requested, shutting down all envoy epochs" instead of the :373 line; record aether_supervisor_drain_duration_* (a metric name that has never existed); leave server_info/unreachable at 0 for the termination probe; keep termination ≤ ~drain-time + grace with exitCode=0; and keep prober deltas at 0 new errors on all tiers and targets, matching this run.
Also worth recording: VictoriaLogs does not ingest the proxy supervisor's logs (service.name carries only registrar/agent/controller/edge), so _msg searches for these lines return false zeros over any historical window — only kubectl logs on a live pod works, which is why the follower was started before each delete.
Activity
bpalermo commentedon Sep 15, 2026
Reproduction result: mechanism CONFIRMED, predicted consequence REFUTED for
kubectl delete podRun 2026-09-15 on talos-main (rev213, quiet cluster), repo HEAD
3c8f9c7. Nothing was fixed or modified; the unit test lives in a scratch snapshot.Confirmed
ctx.Done().supervisor.go:289-290—case <-lp.ctx.Done(): return lp.s.handleShutdown(lp.ctx).lp.ctxiscmd.Context()→ctrl.SetupSignalHandler(), cancelled on SIGTERM.adminprobe.go:271doescontext.WithTimeout(ctx, readyPollInterval)on an already-cancelled parent. Unit test, production-shaped supervisor with a fake admin answeringstate:LIVE, restart_epoch:0(our own epoch, explicitly not mid-handoff): sanity probe on a healthy ctx →live=true; 5 probes on the cancelled ctx →live=falsein 4.8µs–48µs, with the fake admin's request and accepted-connection counters unchanged.aether_supervisor_admin_probes_total{aether_supervisor_probe_endpoint="server_info"}recordedresult="unreachable"exactly once — at its SIGTERM (w03: 1 at the 22:07:00 scrape; w05: 1 at 22:08:30), whileresult="live"was climbing +10/30s right up to that scrape (41,720 / 41,744) andenvoy_server_state{node=…}was0(LIVE) at every step. The otherserver_infocall sites did not run in that window.hotrestart/supervisor.go:373 "termination requested mid-handoff; waiting for successor to terminate our envoy"194ms / 195ms after the delete — while Envoy was LIVE at our own epoch and the replacement Envoy would not start for another 4.3–6.3s.awaitProtocolTerminationhas no deadline and no ctx (:742-753, bare<-s.childExited). Unit test: still blocked at 3.0s, child still tracked and never signalled (no SIGTERM, no drain,drainCompletednever recorded); it returned only when the child was killed externally.Note the comment conflict is real but inverted from how the issue frames it:
:364-365promises "a deadline fallback", while the function's own comment at:735-741says it "deliberately imposes NO deadline" and explains why (killing the parent early aborts the successor with errno 111).:364-365is the stale one.Controls that isolate the cause: same supervisor + same LIVE fake admin but a non-cancelled ctx → drain branch in 30ms, real probe, child SIGTERMed and reaped. And with a live ctx but admin LIVE at epoch 1 (a genuine handoff) → correctly blocks. So the branch logic is sound; the context it is selected with is the bug.
Refuted — what actually happens on
kubectl delete podTwo samples,
kubectl delete pod(not a rollout restart), log follower started before the delete, 1 Hz pod-JSON poller to retain the terminated state.terminationGracePeriodSeconds: 180.dk4b4ltl7q:373mid-handoff lineexitCode=0 reason=Completed(both containers)exitCode=0 reason=Completed(both containers)Not the grace period (23s/21s vs 180s), not 137, and Envoy was drained.
Why: the
aether-proxyDaemonSet creates the replacement pod on the same node within ~1s of the deletionTimestamp, and that pod's Envoy performs a genuine cross-pod hot restart (shared--base-id=0), becoming the successor that protocol-terminates the parent. Akubectl delete podself-rescues into exactly the surge-roll path — the same reason every hitless-rollout validation and soak has been green.Data-plane cost: zero
sum by (node,tier,target,result) (aether_probe_requests_total{result!="success"})over 22:04:00–22:11:00Z, fleet-wide, returns one series: a pre-existingprober-mgf4w / mesh_dns / *.svc.cluster.local / timeout = 1, flat at 1 at every step and already present in the pre-delete baseline. Successes climbed linearly through both windows (+300/30s per tier, both targets, both nodes). 0 new liveness errors, 0 newdns_*, 0 newhttp_error, 0 new timeouts. All 5 proxies back to 2/2 Ready (replacements Ready at +93s and +33s).Falsifiable prediction from the report
aether_supervisor_drain_duration*does not exist as a metric name in Prometheus at all, while its siblingaether_supervisor_handoff_duration_seconds_*from the same meter does — consistent withs.shutdown()never completing in production. Caveat: a process SIGKILLed at the grace period would not flush its final export either, so absence alone is not conclusive; the log evidence above is what settles it.Residual exposure — why this should still be fixed
The branch is now unconditional, so correctness on every termination depends entirely on a successor appearing. Where one cannot appear — graceful node shutdown, node deletion/scale-down,
kubectl delete daemonsetor a chart uninstall, or a replacement stuck Pending/ImagePullBackOff/unschedulable —awaitProtocolTerminationblocks with no deadline until SIGKILL at 180s, with no drain and connections open. That case is reproduced in the unit test; it is not reproducible with pod deletes alone on this DaemonSet, so I did not induce it on-cluster (it would have required editing shared config).Fix ordering matters: do not just add a deadline —
:735-741explains why there isn't one. Fix the ctx first so the branch is entered only when genuinely mid-handoff (the repo already has the idiom, added for #662:common/telemetry/setup/lifecycle.go:23DetachedTimeout=context.WithTimeout(context.WithoutCancel(parent), d)), and only then add a bounded no-successor fallback.Grading a fix against this baseline
On
kubectl delete podof anaether-proxy, a correct fix must: log:377 "termination requested, shutting down all envoy epochs"instead of the:373line; recordaether_supervisor_drain_duration_*(a metric name that has never existed); leaveserver_info/unreachableat 0 for the termination probe; keep termination ≤ ~drain-time + grace withexitCode=0; and keep prober deltas at 0 new errors on all tiers and targets, matching this run.Also worth recording: VictoriaLogs does not ingest the proxy supervisor's logs (
service.namecarries only registrar/agent/controller/edge), so_msgsearches for these lines return false zeros over any historical window — onlykubectl logson a live pod works, which is why the follower was started before each delete.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
fix(proxy-supervisor): probe the admin endpoint on a detached ctx at …
fix(proxy-supervisor,chart): bound the mid-handoff wait by the pod's …
fix(supervisor): probe on a detached ctx, bound the successor wait by…
perf(proxy): split the hot-restart supervisor out of the agent binary (…
perf(proxy): split the hot-restart supervisor out of the agent binary (…
fix(supervisor): on SIGTERM wait (bounded) for the surge successor be…