Skip to content

Commit 7f27b32

Browse files
committed
resolve both ipv4 and ipv6
1 parent 6278da6 commit 7f27b32

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,21 @@ class DnsResolver implements Resolver {
297297

298298
private async lookup(hostname: string): Promise<TcpSubchannelAddress[]> {
299299
if (process.env[DNS_RESOLUTION_ENV] === 'true') {
300-
const records = await this.independentResolver.resolveAny(hostname);
301-
const addressList = records.filter(addr => {
302-
addr.type === 'A' || addr.type === 'AAAA';
303-
}) as unknown as { address: string }[];
300+
const records = await Promise.allSettled([
301+
this.independentResolver.resolve4(hostname),
302+
this.independentResolver.resolve6(hostname),
303+
]);
304304

305-
return addressList.map(addr => ({
306-
host: addr.address,
307-
port: +this.port!,
308-
}));
305+
return records
306+
.reduce<string[]>((acc, result) => {
307+
return result.status === 'fulfilled'
308+
? [...acc, ...result.value]
309+
: acc;
310+
}, [])
311+
.map(addr => ({
312+
host: addr,
313+
port: +this.port!,
314+
}));
309315
}
310316

311317
/* We lookup both address families here and then split them up later

0 commit comments

Comments
 (0)