Skip to content

fix(mesh-dns): detect a wedged resolver and forward TCP queries over TCP - #596

Merged
bpalermo merged 1 commit into
mainfrom
fix/mesh-dns-self-check-tcp-forward
Jul 26, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/mesh-dns-self-check-tcp-forward

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Two of the follow-ups explicitly deferred by #586, in one PR because both live in the resolver's server.go.

Fix 1 — wedge detection

The readiness gate wrote its pod-local marker once, right after the listeners bound (Start → writeReadyMarker), and never re-verified that queries were actually being answered. A resolver whose serve path wedged stayed Ready forever while the CNI kept DNAT-ing every managed pod's :53 at something that answered nothing.

A watchdog (agent/internal/meshdns/selfcheck.go) now exercises the handler every 30s by calling ServeDNS in-process over an in-memory dns.ResponseWriter.

Why not a network self-query: the daemon binds HOST_IP:18054 with SO_REUSEPORT so a surge successor can co-bind, which means a query to that address can be answered by the peer pod — the exact false-ready trap #580 rejected a tcpSocket probe over. Only an in-process call can prove this process answers.

Why this probe name (_selfcheck._aether.<meshDomain>.):

  • under the mesh domain, so it always takes the authoritative path and is never forwarded — the check cannot fail merely because kube-dns is down;
  • both labels start with _, which is not a legal DNS-1123 Kubernetes namespace or Service name, so the record table can never hold this key. The answer is therefore deterministic on a cluster with zero mesh services: NXDOMAIN once records are populated, SERVFAIL while still cold. Both are authoritative and both prove the handler ran end to end (name parse → record-table lock → reply write);
  • it is a well-formed <svc>.<ns> name, so it goes through the record-table lookup — a wedge that is a stuck s.mu is caught, not skipped.

Each check runs on its own goroutine and is awaited with a 5s timeout: a wedged handler never returns, and blocking the watchdog on it would defeat the point. Three consecutive failures remove the ready marker so the exec readiness probe flips the pod NotReady and the surge/rollout machinery can react; a single pass restores it. The watchdog starts only after the bind has already written the marker, so it can never flap a starting pod.

Fix 2 — UDP-only forward client truncating TCP-originated queries

forward() used a single &dns.Client{Net: "udp"}. Since the CNI DNATs TCP :53 as well, a query that arrived over TCP — from a client that had already decided it wants an answer too big for a datagram — was relayed over UDP and could come back with TC=1, which we recorded as a clean forwarded while the client looped or failed.

  • inbound protocol is read off the ResponseWriter's RemoteAddr() (*net.TCPAddr vs *net.UDPAddr);
  • TCP in → TCP out;
  • a truncated UDP reply is retried over TCP and the full answer returned, re-packed to the client's advertised EDNS0 size (512-byte floor). If the TCP retry itself fails, the upstream's TC=1 reply is passed through rather than a SERVFAIL;
  • two clients (udp/tcp) rather than one whose Net is mutated under concurrent serve goroutines;
  • DialTimeout/ReadTimeout/WriteTimeout are now explicit. miekg/dns was already applying an implicit 2s (its unexported dnsTimeout) to each; this pins the same value so the bound is visible and cannot move under a dependency bump.

Metrics

instrument notes
aether.mesh_dns.self_check_total{result=ok|fail} counter
aether.mesh_dns.last_answered_timestamp_seconds Float64ObservableGauge; stamped by real traffic on the hot path (one atomic store) as well as by the watchdog, so a busy resolver never looks idle and a bound-but-blind one stops advancing
aether.mesh_dns.responses_truncated_total replies that arrived TC=1 and required the TCP retry
aether.mesh_dns.queries{result,proto} new proto=udp|tcp attribute (the duration histogram keeps result only, to avoid doubling 15 buckets)

Notes

  • No semantic change to EDNS0 OPT echo, NODATA-for-non-A, the never-forward-the-mesh-zone rule, SO_REUSEPORT, marker-after-bind, or the snapshot envelope/heartbeat.
  • No charts/ change: the existing exec readiness probe already stats the marker, which is exactly the lever the watchdog pulls.
  • The test-only fakeResponseWriter is retired in favour of the production memResponseWriter the watchdog uses — one implementation, not two.
  • Slim dep graph re-proven: somepath(//agent/cmd/mesh-dns:mesh-dns, @io_k8s_sigs_controller_runtime//...) and the @com_github_envoyproxy_go_control_plane//... equivalent are both empty.

Follows #586.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

Two deferred follow-ups from #586, in one PR because both live in the
resolver's server.go.

Wedge detection. The readiness gate wrote its pod-local marker once, right
after the listeners bound, and never re-verified that queries were being
answered. A resolver whose serve path wedged stayed Ready forever while the
CNI kept DNAT-ing every managed pod's :53 at it. A watchdog now exercises the
handler every 30s by calling ServeDNS in-process over an in-memory
ResponseWriter -- never over the network, because SO_REUSEPORT means a query
to HOST_IP:18054 can be answered by the PEER pod during a surge, the exact
false-ready trap #580 rejected a tcpSocket probe over. The probe name is the
reserved "_selfcheck._aether.<meshDomain>": under the mesh domain so it takes
the authoritative path and never depends on kube-dns, and spelled with
underscore labels that can never be a DNS-1123 namespace/Service, so the
answer is deterministic (NXDOMAIN when populated, SERVFAIL while cold) on a
cluster with zero mesh services. Three consecutive failures remove the ready
marker so the exec probe flips the pod NotReady and the rollout machinery can
react; a single pass restores it. The watchdog starts only after the bind has
already written the marker, so it can never flap a starting pod.

Forward-path transport. forward() used one dns.Client pinned to "udp", so a
query that arrived over TCP -- reachable in production, the CNI DNATs TCP :53
too -- was relayed over UDP and could come back TC=1, recorded as a clean
"forwarded" while the client looped. There are now two clients: TCP in means
TCP out, and a truncated UDP reply is re-fetched over TCP and re-packed to the
client's advertised size. Both clients state DialTimeout/ReadTimeout/
WriteTimeout explicitly at the 2s that miekg/dns was applying implicitly.

New instruments: self_check_total{result}, last_answered_timestamp_seconds
(stamped by real traffic too, so a busy resolver never looks idle),
responses_truncated_total, and a proto=udp|tcp attribute on the query counter.
The test fake ResponseWriter is retired in favour of the production
memResponseWriter the watchdog uses.

Follows #586.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
@bpalermo
bpalermo merged commit c4f7bb8 into main Jul 26, 2026
15 checks passed
@bpalermo
bpalermo deleted the fix/mesh-dns-self-check-tcp-forward branch July 26, 2026 12:32
bpalermo added a commit that referenced this pull request Jul 26, 2026
…598)

Completes the deferred qtype/nodata half of the mesh-DNS query-metric
breakdown. #596 already gave aether.mesh_dns.queries its proto attribute and
the responses_truncated_total counter; this is the rest.

The `answered` result conflated two operationally different things: a real A
hit, and the NODATA reply a known mesh name gets for a non-A type (AAAA), which
exists so the name consistently EXISTS for c-ares. A healthy mesh shows a
steady NODATA trickle from the AAAA half of every dual-stack lookup, so
conflated, NODATA rising against real hits — clients failing over to IPv6, or a
record table that stopped producing usable A records — is invisible. They are
now separate result values. NODATA still counts as an answer for
last_answered_timestamp_seconds: it is an authoritative reply produced from the
record table by a handler that ran end to end.

The new qtype attribute is BUCKETED, never raw. DNS defines ~90 query types and
the CNI DNATs every managed pod's :53 straight at this resolver, so an
arbitrary client could otherwise inflate the counter's series count at will.
Everything unrecognised collapses to `other`, bounding the counter at
8 qtype x 6 result x 2 proto = 96 series per node. qtype is deliberately NOT
added to the duration histogram: 15 explicit buckets make each extra dimension
expensive, and latency here is decided by the path taken — which `result`
already names — not by the type asked for.

Metrics-only: no resolver semantics change (EDNS0 echo, NODATA-for-non-A,
never-forward-the-mesh-zone, SO_REUSEPORT, the self-check watchdog, TCP
forwarding and the snapshot envelope are all untouched).

Follows #586.


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

Co-authored-by: Claude <[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

Development

Successfully merging this pull request may close these issues.

1 participant