Skip to content

fix(agent): bound the DNS retransmit budget and stop hiding resolution stalls as timeouts (#726) - #728

Merged
bpalermo merged 2 commits into
mainfrom
fix/726-dns-retransmit-budget
Sep 6, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/726-dns-retransmit-budget

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Closes #726 (mechanism confirmed in #726 (comment)).

The hypothesis in the issue is refuted

#726 proposed that the mesh-domain path is served by an :authority-named on-demand cluster whose endpoints miss the DRAINING-aware health the service cluster gets. It isn't, on either the data or the code:

  • The failing requests never reach Envoy. Across 12:29:30–12:32:00Z on 2026-09-06 there is not one non-200 source-reporter access log anywhere in the mesh — no UT, no UF, no URX, no DC, no 503. Control-tested both ways so this is not a false zero: response_flags:"UT" returns the k6 504s at 05:54:56Z and NOT response_code:"200" returns a DC on w04 at 12:44:47Z.
  • Both paths are one data path. For both authorities in the same seconds, downstream_local_address is 10.107.111.199:18081 (echo's ClusterIP), upstream_cluster is aether-test/echo, and upstream_host rotates over all three replicas. mesh-DNS returns the mesh Service's ClusterIP, never pod IPs, so there is no pod pinning.
  • The alias cluster shares the EDS resource. echo.aether-test.aether.internal:18081 sets EdsClusterConfig.ServiceName to the bare aether-test/echo (agent/internal/xds/cache/cluster.go:401-421), and buildHTTPEndpointBuckets appends the same *LbEndpoint pointer into every bucket, so HealthStatus_DRAINING reaches every cluster shape by construction. feat(agent): two-phase drain — DRAINING first, pool-close after delay #152 cannot diverge between them — and it never engages here anyway, since rolling aether-proxy deletes no echo pods.

The confirmed mechanism

The rev204 deploy rolled aether-mesh-dns too, which the issue's timeline missed. On main-worker-02:

12:30:39.383Z  warm-started mesh-DNS records from snapshot   generation=6 records=14
12:30:39.632Z  mesh DNS resolver listening  addr=192.168.0.61:18054  reusePort=true

The DaemonSet is maxSurge:1 / maxUnavailable:0, readiness is an exec probe with initialDelaySeconds:1, periodSeconds:15, and there is no preStop and no drain. Successor binds at :39.63, its first readiness probe passes at ≈:40.6, the DS controller deletes the predecessor, and Server.Start closes the SO_REUSEPORT UDP socket immediately (agent/internal/meshdns/server.go:493-497). While both sockets are in the reuseport group the kernel hashes each datagram to one of them; a datagram steered at the departing socket in the closing window is silently discarded.

The client then waits the stock resolv.conf timeout:5, and Go's resolver singleflights by name, so that one lost packet stalls every concurrent lookup of that name:

last mesh-domain access log before the hole 12:30:40.841Z
first after 12:30:45.947Z
gap 5.106 s = the default resolv.conf retransmit
same prober, svc.cluster.local, same window 81 records, continuous at 5.06/s, no gap
prober counter …aether.internal 17725 → 17741 (+16)
prober counter …svc.cluster.local 18016 → 18016 (+0)

The arithmetic closes: probes issued in the first ~3.1 s of the 5.1 s stall blow their own 2 s deadline (3.1 × 4.99 ≈ 16); the rest were still queued when resolution completed and were released in a visible pile-up — three requests inside 1 ms at 12:30:45.947/.948/.948, twelve inside 0.6 s, far above the 5/s tick.

The mesh-domain path is not disadvantaged. Largest single burst per prober over 24h:

prober (node) svc.cluster.local aether.internal
prober-5p56l (w01) 81 78
prober-qqwvb (w03) 35 26
prober-gz7gf (w05) 7 19
prober-sw777 (w02) 7 16
prober-5bt7w (w04) 9 1

The biggest burst in the fleet is on cluster.local, three of five probers have their worst there, and every prober has more cluster.local timeouts lifetime than mesh-domain ones. Both names lose the same coin flip; the three samples in the issue caught the mesh side three times.

The change

1. Bound the retransmit cost — controller/internal/podmutate

The pod-mutating webhook now injects options timeout:1 attempts:3 alongside the existing ndots. The resolver a managed pod talks to is node-local (the CNI DNATs :53 to the node's mesh-DNS), so a query that gets no answer is a dropped one, not a slow one — 1 s is generous, and 3 attempts leave a 3 s worst case against the 10 s the defaults allow. A lost datagram costs ~1 s instead of 5 s: under the prober's 2 s budget and under essentially any client's.

  • Fail-open (a resolv.conf option), and it covers every managed pod, not the prober — so it also fixes the symmetric cluster.local bursts including the 81 on w01.
  • An option the workload author already declares is never overridden.
  • Derived constants rather than flags, for the same reason ndots is derived from --mesh-domain (the retired --pod-ndots): the value follows from the topology, not from an operator preference. No chart change, so no Chart.yaml bump.

2. Make the class observable — prober/internal/prober

classifyErr tested ctx.Err() before the *net.DNSError branch. The probe budget (2 s) is shorter than the resolver retransmit (5 s), so ctx.Err() was always DeadlineExceeded by the time the error surfaced, and dns_timeout was structurally unreachable for exactly the failure it exists to name. Three separate investigations read "dns_* is zero" as "DNS is healthy" when it only ever meant "DNS never failed fast". The function's own comment already prescribed DNS-first; the code contradicted it.

The reorder is safe because *net.DNSError is produced only by resolution: Go returns one (with IsTimeout set) when the deadline cancels a lookup in flight, and a plain OpError with no DNSError inside when the deadline lands on a post-resolution connect. Connect stalls still classify as timeout.

Every pre-existing classifyErr subtest passed context.Background(), which is precisely why this survived. The new subtests pin the already-expired-context case in both directions.

MeshDNSResolutionFailing already matched dns_timeout|timeout, so alerting behaviour is unchanged; its comment (which documented the misconception) is corrected.

Not in this PR

Eliminating the datagram loss itself. A post-SIGTERM lame-duck window in Server.Start (drop the ready marker first, keep serving briefly, then close) would narrow it, but the drop is a kernel reuseport-group race at socket close and cannot be fully closed from userspace without eBPF socket steering. Bounding the client's retransmit is what removes the user-visible outage; narrowing the window is second-order. Worth its own issue.

Generated xDS

Unchanged. Nothing in this PR touches the xDS cache or proxy packages, and //test/envoy_validate is unaffected.

Validation on talos-main

The webhook mutates on CREATE only, so existing pods keep the old resolv.conf until recreated. Sequence:

  1. Deploy the controller and prober images, then recreate the prober DaemonSet pods (kubectl -n aether-test rollout restart ds/prober) so they pick up the new dnsConfig. Confirm on one:
    kubectl -n aether-test get pod <prober> -o jsonpath='{.spec.dnsConfig}' → must show ndots:2, timeout:1, attempts:3.
  2. Baseline the counters, then run ≥10 aether-mesh-dns DaemonSet rolls under steady prober load (this is the trigger — not the proxy roll). Ten rolls is the floor: the historical hit rate is ~1 in 3, so 10 gives ~97% power to see at least one pre-fix-sized burst if the fix did nothing.
  3. Per roll, per path, count the delta:
    aether_probe_requests_total{tier="mesh_dns",result="timeout",target="echo.aether-test.aether.internal:18081"}
    aether_probe_requests_total{tier="mesh_dns",result="timeout",target="echo.aether-test.svc.cluster.local:18081"}
    
    Use raw per-series deltas, not rate()/increase() — the counters are OTLP-pushed and rate() lies across scrape gaps.
  4. Pass: no burst above ~2 on either path in any roll (a 1 s stall is well inside the 2 s probe budget, so a lost datagram should now be invisible). Any burst ≥5 means the retransmit budget did not reach that pod — check its dnsConfig first.
  5. New signal to watch: should a resolution stall still occur, it now lands in result="dns_timeout" rather than result="timeout". A non-zero dns_timeout after this deploy is the fix working as an observability change, not a regression — grade dns_timeout + timeout together against the old timeout baseline.
  6. Also confirm no collateral: aether_probe_requests_total{result="dns_nxdomain"} stays at its baseline (a too-aggressive retransmit would surface as spurious NXDOMAIN from truncated search-list walks).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 6, 2026 10:01
…n stalls as timeouts (#726)

The roll-correlated 16-31 request bursts on `<svc>.<ns>.aether.internal:18081`
are not a data-plane defect. The failing requests never reach Envoy: across the
2026-09-06 12:29:30-12:32:00Z burst there is not one non-200 source access log
anywhere in the mesh (control-tested both ways), while the prober's per-path
counter steps +16. The mesh-domain and cluster.local spellings resolve to the
same ClusterIP, hit the same capture listener, and are served by the same
`aether-test/echo` EDS resource, so nothing downstream of resolution can produce
a one-path burst.

What happens instead: mesh-DNS rolls with maxSurge:1/maxUnavailable:0 and no
preStop, so the predecessor's SO_REUSEPORT UDP socket is closed the moment the
successor's first readiness probe passes. A datagram steered at the departing
socket in that window is silently discarded. The client then waits the stock
resolv.conf `timeout:5`, and because Go's resolver singleflights by name, that
one lost packet stalls every concurrent lookup of that name for the full 5s.
Measured gap: 12:30:40.841Z -> 12:30:45.947Z = 5.106s, with the queued probes
released in a visible pile-up on resume. Probes issued in the first ~3.1s blow
their own 2s budget (3.1 x 4.99 = 16); the rest complete late.

Two changes:

- podmutate injects `options timeout:1 attempts:3` alongside ndots. The resolver
  a managed pod talks to is node-local, so 1s is generous, and 3 attempts leave
  a 3s worst case against the 10s the defaults allow. This turns a lost datagram
  from a 5s per-name outage into a ~1s hiccup, under the prober's 2s budget and
  under essentially any client's. An option the workload already declares is
  never overridden. Derived constants, not flags, for the same reason ndots is.

- The prober classifies resolution before its own deadline. The probe budget
  (2s) is shorter than the resolver retransmit (5s), so ctx.Err() was ALWAYS
  DeadlineExceeded by the time the error surfaced and `dns_timeout` was
  structurally unreachable for exactly the failure it names. Three separate
  investigations read "dns_* is zero" as "DNS is healthy" when it only ever meant
  "DNS never failed FAST". The function's own comment already prescribed this
  ordering; the code contradicted it.

The aggregate refutes the mesh-domain framing outright: over 24h the largest
single burst in the fleet is 81 on the cluster.local path (w01), three of five
probers have their worst burst there, and every prober has more cluster.local
timeouts than mesh-domain ones. Both names lose the same coin flip; the three
samples in the issue caught the mesh side three times.

Not addressed here, and worth its own issue: the datagram loss itself. A
post-SIGTERM lame-duck window in the mesh-DNS server would narrow it, but the
drop is a kernel reuseport-group race at socket close and cannot be fully closed
from userspace without eBPF socket steering. Bounding the client's retransmit is
what removes the user-visible outage.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit bcf2352 into main Sep 6, 2026
18 checks passed
@bpalermo
bpalermo deleted the fix/726-dns-retransmit-budget branch September 6, 2026 13:06
bpalermo added a commit that referenced this pull request Sep 6, 2026
…onds buckets (#732) (#733)

aether_probe_request_duration_seconds records time.Since(start).Seconds() but
took the OTel SDK's default explicit boundaries (0, 5, 10, 25 ... 10000), which
are tuned for MILLISECONDS. With seconds-valued observations the first bucket is
"<= 5 s", so a healthy 2 ms probe and a timed-out 2 s probe are the same bucket:
control-tested on talos, all 18,394 pre-fix ~2 s timeout observations on one
prober sit in le=5, identical to +Inf, and every derived quantile reads flat.

Set explicit seconds boundaries on the instrument
(metric.WithExplicitBucketBoundaries, honoured by the pinned otel metric v1.44 --
no View needed), chosen so healthy sub-10 ms probes, the 1 s resolver retransmit
(#728), the 2 s probe budget and the 5 s legacy retransmit each land in their own
bucket. Name and unit are unchanged.

Swept every histogram in the repo for the same mistake and fixed the three others
that recorded seconds into the millisecond defaults:
aether.agent.snapshot.duration, aether.agent.liveness.promotion_delay_seconds,
aether.registrar.sync.duration and aether.replicator.sync.duration. mesh-DNS,
the supervisor and the CNI plugin already carried explicit boundaries.

The prober test asserts the boundaries on the EXPORTED data point via an
sdkmetric ManualReader, so it covers the option actually reaching the SDK, and
pins that a 2.0 s observation lands in le=2 and not in le=1.5.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 6, 2026
…roven serving (#729) (#734)

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.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[email protected]>
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