Avoid http2 IPv6 handling bug

This commit is contained in:
murgatroid99 2019-08-29 14:11:19 -07:00
parent ee4985886d
commit 889d1d3093
1 changed files with 15 additions and 1 deletions

View File

@ -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<string[]>;
if (semver.satisfies(process.version, IPV6_SUPPORT_RANGE)) {
aaaaResult = resolve6Promise(hostname);
} else {
aaaaResult = Promise.resolve<string[]>([]);
}
/* 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 */