diff --git a/packages/grpc-js/src/resolver-dns.ts b/packages/grpc-js/src/resolver-dns.ts index ff91a8f2..c094407a 100644 --- a/packages/grpc-js/src/resolver-dns.ts +++ b/packages/grpc-js/src/resolver-dns.ts @@ -21,6 +21,7 @@ import { registerDefaultResolver, } from './resolver'; import * as dns from 'dns'; +import * as semver from 'semver'; import * as util from 'util'; import { extractAndSelectServiceConfig, ServiceConfig } from './service-config'; import { ServiceError } from './call'; @@ -60,6 +61,14 @@ const DNS_REGEX = /^(?:dns:)?(?:\/\/\w+\/)?(\w+)(?::(\d+))?$/; */ const DEFAULT_PORT = '443'; +/** + * The range of Node versions in which the Node issue + * https://github.com/nodejs/node/issues/28216 has been fixed. In other + * versions, IPv6 literal addresses cannot be used to establish HTTP/2 + * connections. + */ +const IPV6_SUPPORT_RANGE = '>= 12.6'; + const resolve4Promise = util.promisify(dns.resolve4); const resolve6Promise = util.promisify(dns.resolve6); @@ -152,7 +161,12 @@ class DnsResolver implements Resolver { if (this.dnsHostname !== null) { const hostname: string = this.dnsHostname; const aResult = resolve4Promise(hostname); - const aaaaResult = resolve6Promise(hostname); + let aaaaResult: Promise; + if (semver.satisfies(process.version, IPV6_SUPPORT_RANGE)) { + aaaaResult = resolve6Promise(hostname); + } else { + aaaaResult = Promise.resolve([]); + } /* We handle the TXT query promise differently than the others because * the name resolution attempt as a whole is a success even if the TXT * lookup fails */