IPv6 localAddress gives EADDRNOTAVAIL #3892

Closed
bmeck opened this Issue Aug 21, 2012 · 10 comments

4 participants

@bmeck

When using http.request I noticed that binding to '::1' and my IPv6 address resulted in EADDRNOTAVAIL

git@master bradleymeck npm>node
> var req = require('http').get({localAddress:'::1'});
undefined
> 
events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: bind EADDRNOTAVAIL
    at errnoException (net.js:781:11)
    at connect (net.js:634:21)
    at Socket.connect (net.js:716:9)
    at asyncCallback (dns.js:67:16)
    at Object.onanswer [as oncomplete] (dns.js:120:9)

Not sure if this is intended but I would presume not.

@bnoordhuis
Node.js Foundation member

I assume your machine is IPv6 enabled?

Can you post the output of strace node -e 'require("http").get({localAddress:"::1"})'? (Or dtruss if it's solaris/freebsd/darwin).

@bnoordhuis
Node.js Foundation member

bind(0xA, 0x7FFF5FBFEEE0, 0x10) = -1 Err#49

errno 49 is EADDRNOTAVAIL so it's coming straight from the kernel. Probably not a node bug but let's see if we can mitigate it. Does { localAddress: '::0' } work? What about { host: '::1' } (i.e. connect to IPv6 address)?

@piscisaureus

I think the clue is this:

socket(0x2, 0x1, 0x0) = 10 0
...
bind(0xA, 0x7FFF5FBFEEE0, 0x10) = -1 Err#49

IOW, an AF_INET socket is created so the bind() call fails when an IPv6 address is specified. This probably happens because when you don't specify an address to connect to, node defaults to 127.0.0.1.

@bmeck

good call binding to an IPv6 when the default sends to an IPv4 was causing problems.

@bnoordhuis
Node.js Foundation member

So I guess the bug is that an IPv6 local address should force the socket to be IPv6. I'm okay with making that change but I wonder what the ramifications are.

On a tangential note, why don't we - assuming the platform supports it - always create IPv6 sockets? Any potential drawbacks?

@bmeck

@bnoordhuis i am not familiar enough with all the platform TCP/IP stacks, http://docs.oracle.com/javase/1.4.2/docs/guide/net/ipv6_guide/#special alludes to the ability for OS's to convert IPv4 to IPv6 if setup right automatically.

@jasnell
Node.js Foundation member

@bnoordhuis ... what was the outcome on this one?

@bnoordhuis
Node.js Foundation member

I don't know / don't remember.

@jasnell
Node.js Foundation member

Quick investigation shows that this appears to be fixed. Closing. Can reopen if new information is received.

@jasnell jasnell closed this May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment