bbc/http-transport

IPv4 is preferred over IPv6

Closed this issue · 1 comments

dns.lookup (as used by http/request) defaults to reordering responses from DNS resolvers to prefer IPv4 over IPv6. (https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).

Specifically:

verbatim When true, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When false, IPv4 addresses are placed before IPv6 addresses. Default: currently false (addresses are reordered) but this is expected to change in the not too distant future. New code should use { verbatim: true }.

We should set this to true to allow dualstack services to be accessed over IPv6 where possible. The verbatim flag can be passed into request.js using something like:

const verbatimDNSLookup = function(domain, opts = {}, callback) {
          opts.verbatim = true; // Do not prefer IPv4 over IPv6. See https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback

          DNS.lookup(domain, opts, function(error, address, family){
            callback(error, address, family);
          });
        }

Then passing verbatimDNSLookup into the calls to request via lookup in the options passed to request.js .

released in v3.5.4