Complete truncated bootstrap DNS replies before deciding hostname availability

perfloop-oss/coredns · Value Kind Confusion

https://perfloop.ai/t/oss/case_tnnf18mfn2

Verdict

VERIFIED · settled 2026-11-15 · merged as coredns/coredns#8778

What happened: The check fails before this change and passes with it.

Hypothesis

Hostname upstreams using the explicit resolver option can fail Corefile startup even when the same resolver has a valid TCP answer. A partially truncated reply can instead leave the configured upstream list incomplete. Deployment frequency and operational impact are unmeasured.

In dnsLookup, both exchanges use a default UDP dns.Client. The code classifies the lookup by the presence of extracted addresses without inspecting r.Truncated. Empty and partial answers therefore stand in for completed resolution even when the DNS truncation flag says the reply is incomplete. The pinned github.com/miekg/dns v1.1.73 client.go:155-169 explicitly says Exchange does not fall back to TCP. The resulting error propagates through lookupHost, resolveHostEntry, expandAndDedup, parseStanza and setup before startup callbacks are installed.

A new native test file, plugin/forward/perfloop_bootstrap_reply_check_test.go, exhaustively enumerated 32 configurations: four UDP reply modes for A, the same four for AAAA, and presence or absence of a second resolver. The modes were empty, complete with two records, empty truncated, and one-record truncated; TCP supplied the complete records. The exact command `go test ./plugin/forward -run '^TestPerfloopBootstrap(PinnedClient|ReplyMatrix)$' -count=1 -timeout=60s -v` completed the enumeration with 24 counterexamples involving truncation. The eight complete-reply controls passed. For example, empty truncated A plus empty AAAA rejected the hostname without TCP; adding a backup selected that resolver instead. A partially truncated A reply supplied only one of the two addresses.

The reduced deterministic test TestPerfloopBootstrapTruncatedReplay uses one hostname TO, one loopback UDP/TCP resolver, and one call to setup. Its replay input is encoded in that test: UDP A is empty NOERROR with truncation set, UDP AAAA is empty NOERROR, and TCP A contains two valid addresses. The exact command `go test ./plugin/forward -run '^TestPerfloopBootstrapTruncatedReplay$' -count=1 -timeout=30s -v` failed with `valid TCP-resolvable hostname rejected: plugin/forward: failed to resolve "upstream.example": no addresses found for "upstream.example"; UDP_A=1 UDP_AAAA=1 TCP_A=0 TCP_AAAA=0`. This is a startup counterexample, not a performance measurement.

The smallest useful Case check is that replay. Establish the completeness property for both A and AAAA, including partial truncated answers, while retaining complete no-data and redundant-resolver controls. The checker layout is provisional; native regression coverage is required by CONTRIBUTING.md:22-25. Replacing this entire path with the system lookup alone would lose the supported explicit-resolver option, so the contribution must preserve that contract.

Merged https://github.com/coredns/coredns/pull/7923, merge ce0e5a6f39a88bf517a7f5cf4eb07c8497aa7312, established startup hostname support and says all unique resolved IPs become upstream targets. Maintainer yongtang's split decision at https://github.com/coredns/coredns/pull/7923#issuecomment-4569037296 separates startup resolution from dynamic refresh. Open https://github.com/coredns/coredns/pull/8132 at head 31435f5022dbcc22a1cb0bc06c85752a2410c5f0 adds TTL-aware background refresh but retains these UDP exchanges without truncation handling; this proposal does not duplicate that work. The open-PR listing was followed to its last page. Local history is shallow; the bounded owner-history API request and the mailing-list search at https://groups.google.com/g/coredns-discuss/search?q=forward%20resolver%20truncated returned HTTP 403, leaving older and off-host overlap unknown.

Prior hyp_cfm6y5sbdt concerns preserving a downstream client's truncation signal during next_on_nodata delegation in Forward.ServeDNS. That distinct handoff repair does not complete bootstrap DNS lookups. User user:4 withdrew hyp_x8my20x81n for uncommon opt-in retry settings, bounded extra queries and no measured harm; that lowers priority for its retry-cap mechanism, not evidence about this startup failure. The same actor's rejected-publication closures for cache cloning and active cancellation provide no technical refutation here.

Change to test: Distinguish unfinished truncated replies from complete address results for both address families, obtaining the complete reply over TCP when needed. Preserve explicit resolver ordering, absolute-name resolution, endpoint deduplication, and resolve-once startup behavior.

Where it lives

perfloop-oss/coredns · plugin/forward/setup.go

Evidence

The check fails before this change and passes with it: `For startup hostname TOs with an explicit resolver, empty or partial truncated UDP A or AAAA replies are retried over TCP at the same resolver and all addresses from a complete TCP answer become upstream targets.`

The check fails before this change and passes with it: `For explicit-resolver bootstrap A and AAAA lookups with no usable answer from the other family, a partial truncated UDP reply contributes no addresses when its TCP retry is empty, fails, or is still truncated.`

Checks: 2 of 2 passed. Verification: no defect found.

Timeline