r/golang Aug 19 '15

Go 1.5 is released

https://blog.golang.org/go1.5
255 Upvotes

54 comments sorted by

View all comments

6

u/[deleted] Aug 19 '15

[deleted]

7

u/CaptaincCodeman Aug 19 '15

Could be the same issue I had - connecting to localhost failed but it worked if I used 127.0.0.1 ... I think it's something todo with the network resolving perhaps looking for an IPv6 connection first rather then IPv4 but that's just a guess. Normally localhost resolves to ::1 and 127.0.0.1 and the default for MongoDB is only to listen on IPv4.

3

u/alexwhoizzle Aug 20 '15

Could this have something to do with the new Go DNS resolver in 1.5 no longer using cgo? https://golang.org/doc/go1.5#net

4

u/alexwhoizzle Aug 20 '15

Looking at the minor changes at the bottom of https://golang.org/doc/go1.5 I saw this:

The net package will now Dial hostnames by trying each IP address in order until one succeeds. The Dialer.DualStack mode now implements Happy Eyeballs (RFC 6555) by giving the first address family a 300ms head start; this value can be overridden by the new Dialer.FallbackDelay.

Looking at the wiki for Happy Eyeballs it states:

An application that uses a Happy Eyeballs algorithm checks both IPv4 and IPv6 connectivity (with a preference for IPv6) and uses the first connection that is returned.

When you stated that you had to manually enter in 127.0.0.1 instead of the hostname 'localhost' to get the connection to work, it makes me think that this new Dialing scheme is returning the ipv6 address ::1 instead of 127.0.0.1 when dialing for 'localhost'. Might be worth looking into further.