Thanks for the follow-up Brett.
> require('dns').lookup('myhost.local', console.log)
{ oncomplete: [Function: onanswer] }
> null '127.0.0.1' 4
This seems to be the heart of the issue, right there.
As a matter of interest, here are some commands that may give a little illumination:
$ wget myhost.local:8080
...
Resolving myhost.local... 127.0.0.1, ::1, fe80::1
Connecting to myhost.local|::1|:8080... connected.
...
The multiple addresses flow from
getaddrinfo, if I recall correctly.
Since the
node.js docs indicate that dns.lookup uses getaddrinfo, I also tried it out in Python:
$ python
>>> import socket
>>> socket.getaddrinfo("myhost.local", 8080)
[(30, 2, 17, '', ('::1', 8080, 0, 0)), (30, 1, 6, '', ('::1', 8080, 0, 0)), (2, 2, 17, '', ('127.0.0.1', 8080)), (2, 1, 6, '', ('127.0.0.1', 8080)), (30, 2, 17, '', ('fe80::1%lo0', 8080, 0, 1)), (30, 1, 6, '', ('fe80::1%lo0', 8080, 0, 1))]
This mirrors what we saw with wget.
It would seem that there are two issues at work:
1. getaddrinfo is returning IPv4 addresses even though the name `myhost.local` is tied only to an IPv6 address in /etc/hosts; and
2. node.js prefers the IPv4 address, and does not fallback to the alternatives upon a connection error.
Does that seem to be about right?
If this is the case, I am somewhat at a loss as to how to get conveniently Node.js to connect using the IPv6 address. A somewhat inconvenient way would be to manually parse the URL, then lookup the hosts with dns.resolve4/6, and try them all in turn.
Many thanks & cheers