File tree 1 file changed +10
-3
lines changed
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
68
68
throw new MongoAPIError ( 'URI must include hostname, domain name, and tld' ) ;
69
69
}
70
70
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.
72
73
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.
73
80
const addresses = await dns . promises . resolveSrv (
74
81
`_${ options . srvServiceName } ._tcp.${ lookupAddress } `
75
82
) ;
@@ -88,10 +95,10 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
88
95
89
96
validateLoadBalancedOptions ( hostAddresses , options , true ) ;
90
97
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.
92
99
let record ;
93
100
try {
94
- record = await dns . promises . resolveTxt ( lookupAddress ) ;
101
+ record = await txtResolutionPromise ;
95
102
} catch ( error ) {
96
103
if ( error . code !== 'ENODATA' && error . code !== 'ENOTFOUND' ) {
97
104
throw error ;
You can’t perform that action at this time.
0 commit comments