Skip to content

Commit 6355e4e

Browse files
Merge branch 'main' into NODE-5968/6.x-container-and-kubernetes-awareness
2 parents b44e631 + eab8f23 commit 6355e4e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: src/connection_string.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
6868
throw new MongoAPIError('URI must include hostname, domain name, and tld');
6969
}
7070

71-
// Resolve the SRV record and use the result as the list of hosts to connect to.
71+
// Asynchronously start TXT resolution so that we do not have to wait until
72+
// the SRV record is resolved before starting a second DNS query.
7273
const lookupAddress = options.srvHost;
74+
const txtResolutionPromise = dns.promises.resolveTxt(lookupAddress);
75+
txtResolutionPromise.catch(() => {
76+
/* rejections will be handled later */
77+
});
78+
79+
// Resolve the SRV record and use the result as the list of hosts to connect to.
7380
const addresses = await dns.promises.resolveSrv(
7481
`_${options.srvServiceName}._tcp.${lookupAddress}`
7582
);
@@ -88,10 +95,10 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
8895

8996
validateLoadBalancedOptions(hostAddresses, options, true);
9097

91-
// Resolve TXT record and add options from there if they exist.
98+
// Use the result of resolving the TXT record and add options from there if they exist.
9299
let record;
93100
try {
94-
record = await dns.promises.resolveTxt(lookupAddress);
101+
record = await txtResolutionPromise;
95102
} catch (error) {
96103
if (error.code !== 'ENODATA' && error.code !== 'ENOTFOUND') {
97104
throw error;

0 commit comments

Comments
 (0)