Repository navigation
CSHARP-6213: Normalize SRV target host names to lower case during SRV polling - #2112
Merged
Merged
Conversation
… polling DNS names are case-insensitive and SDAM requires host names to be normalized to lower case. DnsMonitor took the SRV target straight from the resolver, so a mixed-case target was compared ordinally against the already-lower-cased lookup domain: mixed case in the parent domain labels failed the parent domain check and the host was excluded from the topology, while mixed case in the leftmost label passed the check and reached the topology unnormalized, where DnsEndPoint's ordinal host comparison made it a different server than its lower-case counterpart.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes SRV polling in DnsMonitor to treat DNS hostnames as case-insensitive by normalizing SRV target hostnames to lower-case before validation and topology updates, aligning with SDAM requirements and preventing silent host exclusion or duplicate server entries.
Changes:
- Normalize
SrvRecord.EndPoint.HosttoToLowerInvariant()and strip a trailing dot before creating theDnsEndPointused for validation and processing. - Add a theory to validate normalization behavior for mixed-case parent-domain labels, mixed-case leftmost label, and resolver-style trailing dot.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/MongoDB.Driver/Core/Clusters/DnsMonitor.cs | Normalizes SRV target hostnames (lower-case + trailing dot removal) before validation and producing DnsEndPoints for polling results. |
| tests/MongoDB.Driver.Tests/Core/Clusters/DnsMonitorTests.cs | Adds coverage ensuring SRV polling normalizes mixed-case and trailing-dot targets to the expected lower-case hostname. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Problem
During SRV polling,
DnsMonitorcompared the host names returned by the resolver against the parent domain case-sensitively. DNS names are case-insensitive (RFC 4343), and SDAM requires that hostnames are normalized to lower-case.The initial seedlist path and the polling path reach the same comparison by different routes, and only one of them folded case:
ConnectionString.ValidateResolvedHostsparses each resolved host throughEndPointHelper.TryParse, which lower-cases. The seed side was lower-cased by the same call during connection string parsing. Both operands are folded, so the ordinal comparison inHasValidParentDomainis correct.DnsMonitor.GetValidEndPointstooksrvRecord.EndPointstraight from the resolver and stripped the trailing dot by hand, never going throughEndPointHelper._lookupDomainNamewas lower-cased (it comes fromClusterSettings.EndPoints), so a raw, possibly mixed-case target was compared ordinally against a lower-cased anchor.