Fix TCP fallback for truncated DNS responses#11
Merged
retlehs merged 2 commits intoretlehs:mainfrom Apr 12, 2026
Merged
Conversation
The query() functions in both internal/dns and internal/mail use UDP by default but never retry over TCP when the response is truncated. Domains with many TXT records (e.g. staffbase.com with 9 TXT records, ~603 bytes) exceed the 512-byte UDP limit, causing the server to set the TC flag and return a partial answer. Records near the end of the response — often SPF — are silently dropped. Check resp.Truncated after the initial UDP exchange and retry with a TCP client, matching the behavior of dig and other resolvers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
query()in bothinternal/dnsandinternal/mailuses UDP only. Domains with many TXT records (e.g. 9+ records, >512 bytes) cause the DNS server to set the TC (truncated) flag. Records near the end of the response — often SPF — are silently dropped.resp.Truncatedafter the UDP exchange and retry over TCP, matching the behavior ofdigand other standard resolvers.mail_test.goanddns_test.gowith local mock DNS servers that simulate truncation, verifying the TCP fallback path and the no-truncation fast path.Reproduction
Test plan
go test ./internal/mail/ -run TestQuery -v— TCP fallback and UDP-only paths passgo test ./internal/dns/ -run TestQuery -v— samego test ./...— full suite (147 tests), zero failures🤖 Generated with Claude Code