Skip to content

CSHARP-6213: Normalize SRV target host names to lower case during SRV polling - #2112

Merged
adelinowona merged 1 commit into
mongodb:mainfrom
adelinowona:csharp6213
Sep 2, 2026
Merged

adelinowona merged 1 commit into
mongodb:mainfrom
adelinowona:csharp6213

Conversation

@adelinowona

@adelinowona adelinowona commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

During SRV polling, DnsMonitor compared 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:

  • Initial discovery — ConnectionString.ValidateResolvedHosts parses each resolved host through EndPointHelper.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 in HasValidParentDomain is correct.
  • Polling — DnsMonitor.GetValidEndPoints took srvRecord.EndPoint straight from the resolver and stripped the trailing dot by hand, never going through EndPointHelper. _lookupDomainName was lower-cased (it comes from ClusterSettings.EndPoints), so a raw, possibly mixed-case target was compared ordinally against a lower-cased anchor.

… 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.
@adelinowona
adelinowona requested a review from a team as a code owner September 1, 2026 15:56
@adelinowona
adelinowona requested review from sanych-sun and a lite review from Copilot September 1, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Host to ToLowerInvariant() and strip a trailing dot before creating the DnsEndPoint used 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.

@sanych-sun sanych-sun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adelinowona adelinowona added the bug Fixes issues or unintended behavior. label Sep 2, 2026
@adelinowona
adelinowona merged commit ce4f9ac into mongodb:main Sep 2, 2026
25 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants