Repository navigation
feat(mesh-dns): keep answering after SIGTERM until the successor is proven serving (#729) - #734
Merged
Merged
Conversation
…roven serving (#729) On an `aether-mesh-dns` roll (maxSurge:1/maxUnavailable:0, SO_REUSEPORT, readiness initialDelaySeconds:1, no preStop, no drain) the DaemonSet controller deletes the predecessor the instant the successor passes its first readiness probe, and `Server.Start` closed the UDP+TCP sockets on the resulting SIGTERM. Every datagram the kernel had already steered into the departing socket's queue was discarded. #726 Phase 1 traced a 5.106 s hole in the mesh-domain access log to exactly one such lost query: Go's resolver singleflights by name, so one drop stalls every concurrent lookup of that name for a full retransmit timeout. #728 shrank that to ~1 s from the client side; the datagram loss was untouched. Lame duck. On SIGTERM the resolver now removes its ready marker (the pod reports NotReady, which is honest — it IS leaving) and KEEPS SERVING until either a successor is observed answering on the same address or `--lame-duck-max` (default 10s) elapses; only then does it close and exit 0. Successor detection is evidence, not a timer. The resolver answers a reserved identity name, `_instance._aether.<mesh-domain>` TXT, with 64 random bits minted at process start — random, because predecessor and successor are each pid 1 in their own container, so a pid stamp could never tell them apart. The lame duck queries that name OVER THE WIRE at its own listen address every 200 ms. Both processes hold a socket in the reuseport group, so the kernel hashes each probe (fresh source port, fresh hash) at one of them; a reply carrying someone else's stamp proves both halves of what must be true before closing — the successor is IN the group and it ANSWERS. Our own stamp, or no reply, is "not yet". A second SIGTERM cuts the window short (reason=signal); the handler is registered only after the shutdown begins, so the first signal can never be mistaken for it. Residual, stated in the code and unfixable from userspace: close() on a reuseport socket can still discard a datagram queued between the last recvfrom and the close. eBPF sk_reuseport steering would be the complete fix. This narrows the exposure from every roll to that instant. Metrics: aether.mesh_dns.lame_duck.exits{reason=successor|deadline|signal} and aether.mesh_dns.lame_duck.duration (seconds, EXPLICIT seconds buckets — the mistake #732/#733 just swept out of the repo). The histogram builder now requires boundaries rather than defaulting, so the next instrument cannot repeat it. INFO lines: "lame duck started", "successor observed" (both stamps), "lame duck deadline reached", "listener closed". Chart 0.92.7 -> 0.92.8: `agent.meshDnsDaemon.lameDuckMax` (default "10s") and a terminationGracePeriodSeconds DERIVED from it (+5s) so the kubelet can never SIGKILL mid-window; no preStop, since the process handles SIGTERM itself. maxSurge:1/maxUnavailable:0 unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This was referenced Sep 6, 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 #729.
The mechanism (from #726 Phase 1)
aether-mesh-dnsrolls withmaxSurge: 1 / maxUnavailable: 0,SO_REUSEPORT, readinessinitialDelaySeconds: 1, no preStop and no drain. The DaemonSet controller deletes the predecessor the instant the successor passes its first readiness probe, the kubelet SIGTERMs it, andServer.Startclosed the UDP + TCP sockets immediately on<-ctx.Done().While both sockets are in the reuseport group the kernel hashes each arriving datagram at one of them. Anything already steered into the departing socket's queue is silently discarded by
close(). #726 measured exactly that: a 5.106 s hole (12:30:40.841Z → 12:30:45.947Z) in one prober's mesh-domain access log, 16 timeouts, and zero non-200 responses anywhere in Envoy — the requests never reached the data plane. One lost datagram, amplified because Go's resolver singleflights by name, so every concurrent lookup of that name waited out the same retransmit.#728 shrank the client-side cost (
options timeout:1 attempts:3,dns_timeoutnow reachable). The datagram loss itself was untouched, and that is this PR.Design as implemented
1. Lame duck on SIGTERM (
agent/internal/meshdns/lameduck.go). On SIGTERM the resolver:mesh-dns-readyreports NotReady) and stops the wedge watchdog, so nothing can restore the marker,--lame-duck-maxelapses, or a second signal arrives,2. Successor detection is evidence, not a timer. The resolver answers a reserved identity name —
_instance._aether.<mesh-domain>TXT, TTL 0 — with 64 random bits minted at process start. The stamp is random rather than pid-derived on purpose: predecessor and successor each run as pid 1 in their own container, so a pid stamp would make them indistinguishable and every window would run to its deadline.The lame duck queries that name over the wire at its own listen address every 200 ms (150 ms timeout). Both processes hold a socket in the reuseport group, so the kernel hashes each probe's 4-tuple at one of them, and a fresh ephemeral source port per probe re-rolls that hash. A reply carrying someone else's stamp proves both halves of what must be true before closing: the successor is in the group (the kernel will steer to it) and it answers (what it is steered gets a reply). Our own stamp, or no reply at all, is "not yet" — never "no successor".
The name is shaped like the existing self-check probe (
_selfcheck._aether.…) and for the same reasons: under the mesh domain so it is answered authoritatively and never forwarded to kube-dns, and both labels start with_, which is not a legal DNS-1123 namespace or Service name, so the record table can never hold a colliding key. It is matched beforeisMeshNameinserve, or it would just be a permanently missing service. Exposure: any pod on the node can ask for it and learn 16 hex characters that mean nothing outside this handoff.3. Second SIGTERM aborts.
signal.NotifyContextconsumes the first signal; the abort handler is registered only after the shutdown begins, so the first signal can never be mistaken for the second.4. Readiness during lame duck. The marker goes first, via the same pod-local marker mechanism the proxy supervisor uses, so the DaemonSet controller's view is honest. This does not affect datagram steering — for a hostNetwork
SO_REUSEPORTlistener the kernel picks which co-bound socket receives each datagram and neither knows nor cares what the kubelet thinks of the pod. That is exactly why the socket has to stay open; readiness alone would change nothing.5. Residual — documented in
runLameDuck, in the chart, and here. The instant ofclose()on a reuseport socket can still drop a datagram the kernel queued between the lastrecvfromand the close. That is a kernel race and is not closable from userspace; eBPFsk_reuseportsteering (drain the departing socket out of the group first) would be the complete fix. The lame duck reduces the exposure from "every roll" to that sub-millisecond race.New flag and values keys
--lame-duck-max(duration, default10s;0disables and restores the pre-#729 close-on-SIGTERM)agent.meshDnsDaemon.lameDuckMax: "10s"0.92.7→0.92.8terminationGracePeriodSecondsis derived fromlameDuckMax(+5 s) by a newaether.meshDns.lameDuckSecondshelper rather than hand-maintained beside it: a grace period shorter than the window means the kubelet SIGKILLs mid-drain, which is precisely the abrupt close this removes. Rendered:"10s"→ 15,"0s"→ 5,"2m"→ 125,"500ms"→ 6, unset → 15 (it follows the binary's own default, not zero). The flag uses the existing{{- if not (kindIs "invalid" …) }}guard so"0s"renders as a real kill switch. NopreStop— the process handles SIGTERM itself, and a preStop sleep would only add a fixed delay in front of a window that already ends on evidence.maxSurge: 1 / maxUnavailable: 0unchanged.Metrics and log lines, as exported by Prometheus
aether.mesh_dns.lame_duck.exits(counter, attrreason)aether_mesh_dns_lame_duck_exits_total{reason="successor|deadline|signal"}aether.mesh_dns.lame_duck.duration(histogram, units, attrreason)aether_mesh_dns_lame_duck_duration_seconds_{bucket,sum,count}Buckets are seconds-oriented:
0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 5, 7.5, 10, 15, 30. That is deliberate — #732/#733 was seconds recorded against OTel's millisecond-tuned defaults, which flattened every value below 5 s into one bucket and is exactly why the #726 validation could not measure this window. The sharedmeterBuilder.histogramnow requires boundaries instead of defaulting to one instrument's set, so the next histogram cannot repeat it.aether.mesh_dns.queriesgains one bounded result value,result="instance_id"(a handful per roll).INFO lines, from the
mesh-dnslogger:Validated locally
bazel test --test_arg=-test.short //agent/internal/meshdns/... //agent/cmd/mesh-dns/... //agent/cmd/mesh-dns-ready/... //common/...— 21/21 pass; full (non-short) meshdns run passes too.reason=successorwith the peer's stamp and the exact window duration; inconclusive probes keep the window open; deadline →reason=deadlinewith the ticker armed at--lame-duck-max; second signal →reason=signal, immediate, winning over a detector that would have succeeded. Plus: stamp uniqueness (100 draws), the identity name answered authoritatively as TXT/NODATA with TTL 0 and not shadowed by a colliding record-table key or by case,probeDialAddrwildcard→loopback,--lame-duck-max=0closing immediately.SO_REUSEPORTUDP/TCP port on 127.0.0.1 (ephemeral), a client streams mesh A queries throughout, the predecessor's context is cancelled (the SIGTERM equivalent). Asserts the predecessor exits withlame_duck.exits{reason="successor"} == 1read off an OTelManualReader, its ready marker is gone, and the query stream stays answered (tolerating at most the one documented close-instant residual). Observed handoff: 0.3–0.8 s.make gazelle,make format-check,bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation(gocognit 15) — all clean.helm lint charts/aetherclean;helm templateverified for the default and for0s / 2m / 500ms / null.On-cluster validation recipe
Not run here — this is deploy-and-measure work for the main session.
0.92.8with the new image, confirmappVersionafter upgrade (publish: concurrent runs race on the same chart version tag — older build overwrote newer (77a7d45 over 95b158e), deploy silently lacked #689 #692 publish race) and that everyaether-mesh-dnspod carries--lame-duck-max=10sandterminationGracePeriodSeconds: 15.kubectl rollout restart daemonset/aether-mesh-dnscycles, waiting for full convergence + a 120 s settle between them.rate(), notincrease()) oftimeout+dns_timeout+connection_error. Pass = 0 on every roll on both paths (echo.aether-test.aether.internal:18081andecho.aether-test.svc.cluster.local:18081).aether_mesh_dns_lame_duck_exits_total{reason}per node. Expectreason="successor"on every node, every roll. Adeadlinemeans the successor never answered — the exposure is unchanged for that node and the roll should be treated as a finding.aether_mesh_dns_lame_duck_duration_seconds_bucket— expect the mass atle=0.25/le=0.5. Anything nearle=10is adeadlinein disguise.log_name:"aether_access_logs" reporter:"source" pod_name:"<prober>" authority:"echo.aether-test.aether.internal:18081"across the roll window; compute consecutive-record gaps. Pass = no gap ≥ 1 s on the mesh-domain path, with thesvc.cluster.localpath as the in-window control. Control-test every negative (response_flags:"URX"field syntax) — LogsQL false zeros have burned three investigations.aether_mesh_dns_ready/watch_active= 1 andrecordssteady on all nodes, no alerts in#alertsduring the window.Worth a follow-up either way: an alert on
increase(aether_mesh_dns_lame_duck_exits_total{reason="deadline"}[1h]) > 0outside a genuine scale-down, in the GitOps repo where the deployed rules live.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr