Repository navigation
Description
Summary
Since #321 shrank the CNAME read buffer to 1232 bytes, a larger UDP answer from a server that ignores the EDNS size is cut, fails to parse, and is skipped as a stray packet, so the lookup waits for its full timeout and is counted as a timeout.
Where
internal/dns/cname.go:117-145internal/dns/cname.go:158
Details
The #321 fix shrank the UDP read buffer from 65535 to ednsPayload (1232): buf = make([]byte, ednsPayload), then n, err := conn.Read(buf), msg.Unpack(reply), and on an unpack error if packet { continue // not a DNS message for us }. A datagram larger than 1232 bytes (a server that ignores the advertised EDNS size and does not set TC) is cut to 1232 bytes on Linux, fails Unpack, and is skipped as if it were someone else's packet; the loop then blocks until the per-type deadline. Go's own resolver uses the same 1232-byte buffer but parses only the header first (p.Start), so it fails at once with a parse error instead of a timeout. Before #321 the 64 KiB buffer read such an answer whole. Assumption: Linux UDP read semantics (silent truncation); on Windows the read returns WSAEMSGSIZE and the lookup fails as "other" instead.
Impact
Against a non-conforming resolver, every CNAME lookup of an affected name costs the full -timeout per attempt and is counted as a timeout, feeding the reliability guard and AutoRate as if the resolver were overloaded. Rare: conforming servers truncate and set TC, which the TCP retry handles.
Steps to reproduce
A test UDP server that replies to a CNAME query with a 1500-byte NOERROR message (padding TXT in additional) without TC; lookupCNAME returns a timeout after the context deadline rather than an error.
Suggested fix
Size the buffer to 65535 again only for the read (reuse one per pooled socket to keep #321's saving), or check the header first: if the ID and question match but the body does not unpack, return an error (or treat as truncated and retry over TCP) instead of continue.
Related: #321
Getting started
- Relevant files:
internal/dns/cname.go - How to run tests:
go test ./...(tests must stay hermetic: use-simulate, a lab zone orinternal/dnstest, never a live domain) - Related docs:
docs/DEVELOPER_GUIDE.md,docs/ARCHITECTURE.md
Filed by repo-audit/full-audit at 0f3b0b6. Severity: low. Effort: S. audit-key: bug|internal/dns/cname.go|cnameExchange
Activity
TMHSDigital commentedon Nov 16, 2026
Fixed in 67bbd98.
cnameExchangenow matches a UDP reply by its header and question alone (replyMatches). A matching answer that filled the 1232-byte read buffer and does not parse (cut silently on Linux, or with WSAEMSGSIZE on Windows) comes back marked truncated, sorawLookupasks again over TCP instead of skipping it until the deadline. A matching answer that fits but does not parse now fails at once, as Go's resolver does. The 1232-byte buffer from #321 is kept.Verified with
TestCNAMEOversizedUDPAnswer(a local UDP server sends a ~1.6 KB NOERROR answer without TC, a local TCP server answers the retry; plus a short malformed answer): it failed before the change (a "message too long" error on Windows, a 5 s timeout for the malformed case) and passes after, on Windows and on Linux (test binary cross-compiled and run under WSL). Full gofmt / vet / golangci-lint /go test ./...gate green.