File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments