@@ -21,6 +21,7 @@ import {
21
21
registerDefaultScheme ,
22
22
} from './resolver' ;
23
23
import * as dns from 'dns' ;
24
+ import * as dnsPromises from 'dns/promises' ;
24
25
import * as util from 'util' ;
25
26
import { extractAndSelectServiceConfig , ServiceConfig } from './service-config' ;
26
27
import { Status } from './constants' ;
@@ -48,7 +49,6 @@ export const DEFAULT_PORT = 443;
48
49
const DEFAULT_MIN_TIME_BETWEEN_RESOLUTIONS_MS = 30_000 ;
49
50
50
51
const resolveTxtPromise = util . promisify ( dns . resolveTxt ) ;
51
- const dnsLookupPromise = util . promisify ( dns . lookup ) ;
52
52
53
53
/**
54
54
* Resolver implementation that handles DNS names and IP addresses.
@@ -63,7 +63,7 @@ class DnsResolver implements Resolver {
63
63
* Failures are handled by the backoff timer.
64
64
*/
65
65
private readonly minTimeBetweenResolutionsMs : number ;
66
- private pendingLookupPromise : Promise < dns . LookupAddress [ ] > | null = null ;
66
+ private pendingLookupPromise : Promise < string [ ] > | null = null ;
67
67
private pendingTxtPromise : Promise < string [ ] [ ] > | null = null ;
68
68
private latestLookupResult : Endpoint [ ] | null = null ;
69
69
private latestServiceConfig : ServiceConfig | null = null ;
@@ -76,12 +76,17 @@ class DnsResolver implements Resolver {
76
76
private isNextResolutionTimerRunning = false ;
77
77
private isServiceConfigEnabled = true ;
78
78
private returnedIpResult = false ;
79
+ private resolver = new dnsPromises . Resolver ( ) ;
80
+
79
81
constructor (
80
82
private target : GrpcUri ,
81
83
private listener : ResolverListener ,
82
84
channelOptions : ChannelOptions
83
85
) {
84
86
trace ( 'Resolver constructed for target ' + uriToString ( target ) ) ;
87
+ if ( target . authority ) {
88
+ this . resolver . setServers ( [ target . authority ] ) ;
89
+ }
85
90
const hostPort = splitHostPort ( target . path ) ;
86
91
if ( hostPort === null ) {
87
92
this . ipResult = null ;
@@ -189,7 +194,7 @@ class DnsResolver implements Resolver {
189
194
* because when looking up a single family, dns.lookup outputs an error
190
195
* if the name exists but there are no records for that family, and that
191
196
* error is indistinguishable from other kinds of errors */
192
- this . pendingLookupPromise = dnsLookupPromise ( hostname , { all : true } ) ;
197
+ this . pendingLookupPromise = this . resolver . resolve ( hostname ) ;
193
198
this . pendingLookupPromise . then (
194
199
addressList => {
195
200
if ( this . pendingLookupPromise === null ) {
@@ -199,7 +204,7 @@ class DnsResolver implements Resolver {
199
204
this . backoff . reset ( ) ;
200
205
this . backoff . stop ( ) ;
201
206
const subchannelAddresses : TcpSubchannelAddress [ ] = addressList . map (
202
- addr => ( { host : addr . address , port : + this . port ! } )
207
+ addr => ( { host : addr , port : + this . port ! } )
203
208
) ;
204
209
this . latestLookupResult = subchannelAddresses . map ( address => ( {
205
210
addresses : [ address ] ,
0 commit comments