Skip to content

refactor(NODE-7313): only use dns.resolve for all types#4846

Merged
PavelSafronov merged 15 commits intomainfrom
NODE-7313
Mar 16, 2026
Merged

refactor(NODE-7313): only use dns.resolve for all types#4846
PavelSafronov merged 15 commits intomainfrom
NODE-7313

Conversation

@durran
Copy link
Copy Markdown
Contributor

@durran durran commented Jan 22, 2026

Description

Refactors all dns resolution to only go through lookup and resolve.

Summary of Changes

  • Refactors dns resolution to only use lookup and resolves
  • Fixes all tests

What is the motivation for this change?

NODE-7313

Release Highlight

Use dns.resolve method for all types of DNS resolution

The driver now uses the method dns.resolve(hostname, rrtype) instead of multiple dns.resolveCname/dns.resolvePtr methods. This reduces the number of methods that need to be supplied to the client.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@tadjik1 tadjik1 marked this pull request as ready for review February 9, 2026 12:08
@tadjik1 tadjik1 requested a review from a team as a code owner February 9, 2026 12:08
PavelSafronov
PavelSafronov previously approved these changes Feb 26, 2026
Copy link
Copy Markdown
Contributor

@PavelSafronov PavelSafronov left a comment

Choose a reason for hiding this comment

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

Changes look good.

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

Refactors the driver’s DNS resolution paths so SRV/TXT/CNAME/PTR lookups consistently route through dns.resolve(...) (and dns.lookup(...) where appropriate), aligning runtime behavior and test stubbing with the unified API.

Changes:

  • Updated SRV polling to use dns.promises.resolve(host, 'SRV') instead of resolveSrv.
  • Updated SRV/TXT connection-string resolution retry logic to use dns.promises.resolve(host, rrtype).
  • Updated GSSAPI canonicalization to use dns.promises.resolve(host, 'PTR' | 'CNAME') and adjusted related unit/manual/integration tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/sdam/srv_polling.ts Switch SRV polling to dns.promises.resolve(..., 'SRV').
src/connection_string.ts Refactor DNS timeout retry helper to use `resolve(..., 'SRV'
src/cmap/auth/gssapi.ts Replace resolvePtr/resolveCname with `resolve(..., 'PTR'
test/unit/sdam/srv_polling.test.ts Update SRV polling DNS stubs/assertions for resolve.
test/unit/connection_string.test.ts Update SRV/TXT stubbing to a single dns.promises.resolve stub with rrtype matching.
test/unit/cmap/auth/gssapi.test.ts Update canonicalization tests to use dns.resolve(..., rrtype) spies/stubs.
test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts Update SRV polling prose test to stub dns.promises.resolve.
test/manual/kerberos.test.ts Update kerberos DNS assertions/stubs to use dns.resolve(..., rrtype) and dns.lookup.
test/integration/initial-dns-seedlist-discovery/initial_dns_seedlist_discovery.prose.test.ts Update seedlist discovery prose test to stub dns.promises.resolve for SRV/TXT.
test/integration/initial-dns-seedlist-discovery/dns_seedlist.test.ts Update DNS timeout tests to stub dns.promises.resolve with rrtype matching.
Comments suppressed due to low confidence (1)

test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts:298

  • sinon.stub(dns.promises, 'resolve') here intercepts all resolve() calls, including the driver's TXT lookup (resolve(host, 'TXT')) during SRV connection string processing. Since this stub always returns SRV records, TXT resolution will return the wrong shape and can break resolveSRVRecord. Prefer scoping the stub with withArgs(<hostname>, 'SRV') (and let 'TXT' call through or reject with { code: 'ENODATA' }).
      // first call is for the driver initial connection
      // second call will check the poller
      resolveSrvStub = sinon.stub(dns.promises, 'resolve').callsFake(async address => {
        expect(address).to.equal(`_${srvServiceName}._tcp.test.mock.test.build.10gen.cc`);
        if (initialDNSLookup) {
          initialDNSLookup = false;
          return initialRecords;
        }
        return replacementRecords;
      });

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dariakp dariakp requested a review from nbbeeken March 13, 2026 20:44
@dariakp dariakp added the Team Review Needs review from team label Mar 13, 2026
@PavelSafronov PavelSafronov merged commit 4b7feb3 into main Mar 16, 2026
30 checks passed
@PavelSafronov PavelSafronov deleted the NODE-7313 branch March 16, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants