Set truncate bit for DNS responses#35
Open
kanashimia wants to merge 1 commit intoletsencrypt:mainfrom
Open
Conversation
UDP buffer is only 512 bytes by default, it is pretty much never enough for the cases when there are multiple DNS records in a single response, so the responses are cut at arbitrary points which causes problems. This fixes that by truncating responses at record boundaries and setting TC bit, DNS clients should then read TC bit and retry over TCP which allows for a 64KB buffer. Truncate function also enables compression if message doesn't fit in the buffer uncompressed but fits if it is compressed. See docs: https://pkg.go.dev/github.com/miekg/dns#Msg.Truncate Was originally found in letsencrypt/pebble#536 (comment)
aarongable
reviewed
Feb 17, 2026
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.
UDP buffer is only 512 bytes by default, it is pretty much never enough for the cases when there are multiple DNS records in a single response, so the responses are cut at arbitrary points which causes problems.
This fixes that by truncating responses at record boundaries and setting TC bit, DNS clients should then read TC bit and retry over TCP which allows for a 64KB buffer.
Truncate function also enables compression if message doesn't fit in the buffer uncompressed but fits if it is compressed.
See docs: https://pkg.go.dev/github.com/miekg/dns#Msg.Truncate
Also here is a link for the source code of Truncate func, with regards to how it handles compression: https://github.com/miekg/dns/blob/ce76cb6c9b5f3b75ff44996597994ae6f13eae28/msg_truncate.go#L29-L51
Plus although I never used go before, Compress is set to false by default anyways from what I understand,
so I removed that
m.Compress = false, it is too confusing otherwise, Truncate overrides that value anyways.Was originally found in
letsencrypt/pebble#536 (comment)
@beautifulentropy
Although pebble now always queries over TCP, other clients still do a UDP->TCP fallback based on a TC bit set.