Make Record.RR() always deterministic#190
Merged
mholt merged 1 commit intolibdns:masterfrom Sep 2, 2025
Merged
Conversation
`SvcParams.String()` used to iterate over keys in a random order, which meant that calling `ServiceBinding.RR()` could return different `Data` for identical records. This commit sorts the keys in lexicographic order, making the result deterministic. Furthermore, since it seems useful for code to assume that it can safely roundtrip between `Record.RR()` and `RR.Parse()` and that `Record.RR()` is deterministic, I've now documented this. These are both already the case, but a formal guarantee should make external usage easier. Related to libdns#189.
mholt
approved these changes
Sep 2, 2025
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.
SvcParams.String()used to iterate over keys in a random order, which meant that callingServiceBinding.RR()could return differentDatafor identical records. This commit sorts the keys in lexicographic order, making the result deterministic.Furthermore, since it seems useful for code to assume that it can safely roundtrip between
Record.RR()andRR.Parse()and thatRecord.RR()is deterministic, I've now documented this. These are both already the case, but a formal guarantee should make external usage easier.Related to #189.
RFC 9460 §2.1 says that we're allowed to place the keys in any order that we want, so I decided to sort the keys lexicographically since that was the easiest to implement. However, the canonical order is to sort by the key index, but this would require for us to hardcode the key↔index mapping.