@@ -20,9 +20,8 @@ import {
20
20
registerResolver ,
21
21
registerDefaultScheme ,
22
22
} from './resolver' ;
23
- import * as dns from 'dns' ;
24
- import * as dnsPromises from 'dns/promises' ;
25
- import * as util from 'util' ;
23
+ import { AnyRecord } from 'dns' ;
24
+ import * as dns from 'dns/promises' ;
26
25
import { extractAndSelectServiceConfig , ServiceConfig } from './service-config' ;
27
26
import { Status } from './constants' ;
28
27
import { StatusObject } from './call-interface' ;
@@ -48,8 +47,6 @@ export const DEFAULT_PORT = 443;
48
47
49
48
const DEFAULT_MIN_TIME_BETWEEN_RESOLUTIONS_MS = 30_000 ;
50
49
51
- const resolveTxtPromise = util . promisify ( dns . resolveTxt ) ;
52
-
53
50
/**
54
51
* Resolver implementation that handles DNS names and IP addresses.
55
52
*/
@@ -63,7 +60,7 @@ class DnsResolver implements Resolver {
63
60
* Failures are handled by the backoff timer.
64
61
*/
65
62
private readonly minTimeBetweenResolutionsMs : number ;
66
- private pendingLookupPromise : Promise < string [ ] > | null = null ;
63
+ private pendingLookupPromise : Promise < AnyRecord [ ] > | null = null ;
67
64
private pendingTxtPromise : Promise < string [ ] [ ] > | null = null ;
68
65
private latestLookupResult : Endpoint [ ] | null = null ;
69
66
private latestServiceConfig : ServiceConfig | null = null ;
@@ -76,7 +73,7 @@ class DnsResolver implements Resolver {
76
73
private isNextResolutionTimerRunning = false ;
77
74
private isServiceConfigEnabled = true ;
78
75
private returnedIpResult = false ;
79
- private resolver = new dnsPromises . Resolver ( ) ;
76
+ private resolver = new dns . Resolver ( ) ;
80
77
81
78
constructor (
82
79
private target : GrpcUri ,
@@ -194,7 +191,7 @@ class DnsResolver implements Resolver {
194
191
* because when looking up a single family, dns.lookup outputs an error
195
192
* if the name exists but there are no records for that family, and that
196
193
* error is indistinguishable from other kinds of errors */
197
- this . pendingLookupPromise = this . resolver . resolve ( hostname ) ;
194
+ this . pendingLookupPromise = this . resolver . resolveAny ( hostname ) ;
198
195
this . pendingLookupPromise . then (
199
196
addressList => {
200
197
if ( this . pendingLookupPromise === null ) {
@@ -203,9 +200,11 @@ class DnsResolver implements Resolver {
203
200
this . pendingLookupPromise = null ;
204
201
this . backoff . reset ( ) ;
205
202
this . backoff . stop ( ) ;
206
- const subchannelAddresses : TcpSubchannelAddress [ ] = addressList . map (
207
- addr => ( { host : addr , port : + this . port ! } )
208
- ) ;
203
+ const subchannelAddresses : TcpSubchannelAddress [ ] = addressList
204
+ . filter ( addr => {
205
+ addr . type === 'A' || addr . type === 'AAAA' ;
206
+ } )
207
+ . map ( addr => ( { host : addr . address , port : + this . port ! } ) ) ;
209
208
this . latestLookupResult = subchannelAddresses . map ( address => ( {
210
209
addresses : [ address ] ,
211
210
} ) ) ;
@@ -258,7 +257,7 @@ class DnsResolver implements Resolver {
258
257
/* We handle the TXT query promise differently than the others because
259
258
* the name resolution attempt as a whole is a success even if the TXT
260
259
* lookup fails */
261
- this . pendingTxtPromise = resolveTxtPromise ( hostname ) ;
260
+ this . pendingTxtPromise = this . resolver . resolveTxt ( hostname ) ;
262
261
this . pendingTxtPromise . then (
263
262
txtRecord => {
264
263
if ( this . pendingTxtPromise === null ) {
0 commit comments