Skip to content

Commit c3d073b

Browse files
George Kampitakisgkampitakis
authored andcommitted
update per comments
1 parent e2a93d1 commit c3d073b

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

packages/grpc-js/src/resolver-dns.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import {
2020
registerResolver,
2121
registerDefaultScheme,
2222
} 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';
2625
import { extractAndSelectServiceConfig, ServiceConfig } from './service-config';
2726
import { Status } from './constants';
2827
import { StatusObject } from './call-interface';
@@ -48,8 +47,6 @@ export const DEFAULT_PORT = 443;
4847

4948
const DEFAULT_MIN_TIME_BETWEEN_RESOLUTIONS_MS = 30_000;
5049

51-
const resolveTxtPromise = util.promisify(dns.resolveTxt);
52-
5350
/**
5451
* Resolver implementation that handles DNS names and IP addresses.
5552
*/
@@ -63,7 +60,7 @@ class DnsResolver implements Resolver {
6360
* Failures are handled by the backoff timer.
6461
*/
6562
private readonly minTimeBetweenResolutionsMs: number;
66-
private pendingLookupPromise: Promise<string[]> | null = null;
63+
private pendingLookupPromise: Promise<AnyRecord[]> | null = null;
6764
private pendingTxtPromise: Promise<string[][]> | null = null;
6865
private latestLookupResult: Endpoint[] | null = null;
6966
private latestServiceConfig: ServiceConfig | null = null;
@@ -76,7 +73,7 @@ class DnsResolver implements Resolver {
7673
private isNextResolutionTimerRunning = false;
7774
private isServiceConfigEnabled = true;
7875
private returnedIpResult = false;
79-
private resolver = new dnsPromises.Resolver();
76+
private resolver = new dns.Resolver();
8077

8178
constructor(
8279
private target: GrpcUri,
@@ -194,7 +191,7 @@ class DnsResolver implements Resolver {
194191
* because when looking up a single family, dns.lookup outputs an error
195192
* if the name exists but there are no records for that family, and that
196193
* error is indistinguishable from other kinds of errors */
197-
this.pendingLookupPromise = this.resolver.resolve(hostname);
194+
this.pendingLookupPromise = this.resolver.resolveAny(hostname);
198195
this.pendingLookupPromise.then(
199196
addressList => {
200197
if (this.pendingLookupPromise === null) {
@@ -203,9 +200,11 @@ class DnsResolver implements Resolver {
203200
this.pendingLookupPromise = null;
204201
this.backoff.reset();
205202
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! }));
209208
this.latestLookupResult = subchannelAddresses.map(address => ({
210209
addresses: [address],
211210
}));
@@ -258,7 +257,7 @@ class DnsResolver implements Resolver {
258257
/* We handle the TXT query promise differently than the others because
259258
* the name resolution attempt as a whole is a success even if the TXT
260259
* lookup fails */
261-
this.pendingTxtPromise = resolveTxtPromise(hostname);
260+
this.pendingTxtPromise = this.resolver.resolveTxt(hostname);
262261
this.pendingTxtPromise.then(
263262
txtRecord => {
264263
if (this.pendingTxtPromise === null) {

0 commit comments

Comments
 (0)