Skip to content

http.request option "family: 6" doesn't enable request over IPv6 #6440

Description

@DimitryDushkin
  • Version: 5.5
  • Platform: Ubuntu 14.04.1
  • Subsystem: http(s)

Seems like family option does nothing with actual DNS resolve to ipv6.
Problem is internal server should only use ipv6. So, instead of

https.get({
    hostname: 'cloud-api.yandex.net',
    path: '/v1/disk/resources?path=/',
    family: 6,
    port: 443,
    protocol: 'https:'
}, (res) => {
    console.log(res);
}).on('error', (e) => {
  console.log(`Got error: ${e.message}`);    // Got error: connect EHOSTUNREACH 213.180.204.127:443
});

i should write

dns.lookup('cloud-api.yandex.net', { family: 6 }, (err, addr, family) => {
    https.get({
        hostname: addr,
        path: '/v1/disk/resources?path=/',
        port: 443,
        protocol: 'https:',
        headers: { host: 'cloud-api.yandex.net' }
    }, (res) => {
        console.log(res);
    }).on('error', (e) => {
      console.log(`Got error: ${e.message}`);
    });
});

Activity

  1. changed the title [-]http.request option "family" do nothing[/-] [+]http.request option "family: 6" do not enable request over IPv6[/+] on Apr 28, 2016
  2. changed the title [-]http.request option "family: 6" do not enable request over IPv6[/-] [+]http.request option "family: 6" doesn't enable request over IPv6[/+] on Apr 28, 2016
  3. added
    confirmed-bugIssues and PRs for confirmed bugs.
    tlsIssues and PRs related to the tls subsystem.
    httpsIssues and PRs related to the https subsystem.
    on Apr 28, 2016
  4. bnoordhuis commented on Apr 28, 2016

    @bnoordhuis
    Member

    Confirmed. The bug is in tls.connect() with a second-order bug in http.Agent#getName(). This patch should fix it:

    diff --git a/lib/_http_agent.js b/lib/_http_agent.js
    index fd74daa..3f3d148 100644
    --- a/lib/_http_agent.js
    +++ b/lib/_http_agent.js
    @@ -102,6 +102,10 @@ Agent.prototype.getName = function(options) {
       if (options.localAddress)
         name += options.localAddress;
    
    +  name += ':';
    +  if (options.family === 4 || options.family === 6)
    +    name += options.family;
    +
       return name;
     };
    
    diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
    index 029d9ac..d42f855 100644
    --- a/lib/_tls_wrap.js
    +++ b/lib/_tls_wrap.js
    @@ -1021,6 +1021,7 @@ exports.connect = function(/* [port, host], options, cb */) {
           connect_opt = {
             port: options.port,
             host: options.host,
    +        family: options.family,
             localAddress: options.localAddress
           };
         }
  5. JungMinu commented on Apr 29, 2016

    @JungMinu
    Member

    @bnoordhuis would you mind if I make a PR to resolve this issue based on your comment?

  6. bnoordhuis commented on Apr 29, 2016

    @bnoordhuis
    Member

    I will but I haven't had time yet to write a robust regression test.

  7. bnoordhuis commented on May 9, 2016

    @bnoordhuis
    Member
  8. dzlk commented on Jun 29, 2016

    @dzlk

    Do you have plans to fix this in v4.x?

  9. bnoordhuis commented on Jun 29, 2016

    @bnoordhuis
    Member

    #6654 is tagged lts-watch-v4.x. It will make its way into a LTS release eventually.

  10. MylesBorins commented on Jun 29, 2016

    @MylesBorins
    Contributor

    I've just backported #6654 to LTS staging. it should be in the next release

  11. dzlk commented on Jun 29, 2016

    @dzlk

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.httpsIssues and PRs related to the https subsystem.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions