Skip to content

CSHARP-5930: [Tiny] Fix unreliable DNS lookup#1970

Open
ajcvickers wants to merge 1 commit intomongodb:mainfrom
ajcvickers:CSHARP-5930h
Open

CSHARP-5930: [Tiny] Fix unreliable DNS lookup#1970
ajcvickers wants to merge 1 commit intomongodb:mainfrom
ajcvickers:CSHARP-5930h

Conversation

@ajcvickers
Copy link
Copy Markdown
Contributor

The test URL uses mongodb+srv://, which causes MongoClientSettings.FromUrl to call url.Resolve() at line 904, which does a real DNS TXT lookup for awssessiontokentest.example.net. That domain doesn't exist, so DNS times out. The test was introduced in 2020 and has always made a real DNS call. Whether it passes depends entirely on how the local DNS resolver handles the awssessiontokentest.example.net query:

  • Your machine: DNS query for example.net times out (your resolver sends it upstream and waits).
  • CI (and possibly many other environments): The DNS server quickly returns NXDOMAIN for .example.net — it's an IANA-reserved domain under RFC 2606, and many resolvers short-circuit it. When NXDOMAIN comes back fast, DnsClient does not throw DnsResponseException for a "timed out or transient error" — it returns an empty response, GetTxtRecords returns an empty list, and GetResolvedOptionsFromTxtRecords on an empty list succeeds silently. The fix is to change mongodb+srv:// to mongodb:// — the SRV scheme is irrelevant to what the test verifies (credential parsing), and it's the only reason any DNS call happens at all.

The test URL uses `mongodb+srv://`, which causes MongoClientSettings.FromUrl to call url.Resolve() at line 904, which does a real DNS TXT lookup for awssessiontokentest.example.net. That domain doesn't exist, so DNS times out.
The test was introduced in 2020 and has always made a real DNS call. Whether it passes depends entirely on how the local DNS resolver handles the awssessiontokentest.example.net query:

- Your machine: DNS query for example.net times out (your resolver sends it upstream and waits).
- CI (and possibly many other environments): The DNS server quickly returns NXDOMAIN for .example.net — it's an IANA-reserved domain under RFC 2606, and many resolvers short-circuit it. When NXDOMAIN comes back fast, DnsClient does not throw DnsResponseException for a "timed out or transient error" — it returns an empty response, GetTxtRecords returns an empty list, and GetResolvedOptionsFromTxtRecords on an empty list succeeds silently.
 The fix is to change `mongodb+srv://` to `mongodb://` — the SRV scheme is irrelevant to what the test verifies (credential parsing), and it's the only reason any DNS call happens at all.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 an unreliable unit test in MongoClientSettingsTests by removing the use of the mongodb+srv:// scheme, which triggers a real DNS TXT lookup during MongoClientSettings.FromUrl parsing and can intermittently time out depending on the environment’s DNS behavior.

Changes:

  • Update the AWS credential parsing test connection string from mongodb+srv:// to mongodb:// to avoid SRV/TXT DNS resolution during the test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ajcvickers ajcvickers marked this pull request as ready for review April 24, 2026 12:25
@ajcvickers ajcvickers requested a review from a team as a code owner April 24, 2026 12:25
@ajcvickers ajcvickers requested a review from adelinowona April 24, 2026 12:25
@ajcvickers ajcvickers changed the title CSHARP-5930: Fix unreliable DNS lookup CSHARP-5930: [Tiny] Fix unreliable DNS lookup Apr 24, 2026
@ajcvickers ajcvickers added the chore Non–user-facing code changes (tests, build scripts, etc.). label Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Non–user-facing code changes (tests, build scripts, etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants