-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: ipv4 chosen first when ipv6 is available #68795
Comments
It looks like we prefer IPv4 since https://go.dev/cl/8360. That does seem to contradict RFC 6555, which says that we should try IPv6 first. That RFC is obsoleted by RFC 8305. The latter requires that we use whichever DNS answer we get first, but we don't seem to do that at all; we collect all the DNS answers before we try opening any connection. Changing this might be as simple as changing |
Our dial algorithm doesn't match the behavior in RFC 8305 at all. We dial each address within a family serially, only trying a fallback address after the previous one has failed. RFC 8305 recommends sorting all addresses into a single list with IPv4 and IPv6 interleaved, and adding racing dials over time. I can't tell if we take into account whether the local system has any IPv4/IPv6 connectivity. I think we don't, which means we'll try to dial addresses for families where we have no local address. These dials should fail quickly, so I don't know how much of a problem that is. Any changes here should take errors into account. When a dial fails, we currently return the error for the first dial attempt made. If our first attempt fails because the system has no connectivity for the address family, and a subsequent attempt fails for some other reason (ECONNREFUSED, say), returning the first error is confusing and masks useful information. This is #18183 and a long standing problem, but we should be careful not to make matters worse. I'm concerned that changing Dial to prefer IPv6 over IPv4 will cause breakage. What's the fallback for users who encounter problems? Maybe there should be a net.Dialer option to set the preferred address family? |
Go version
go version go1.22.5 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
On a network where IPv4 is blocked:
This shows that it incorrectly tried IPv4 first, and then fell back to IPv6.
(The above output is from running on Linux ARM with the netgo build tag, not on macos.)
What did you expect to see?
As per the documentation in net, it should follow "happy eyeballs" and dial IPv6 first, and only fall back to IPv4 if that doesn't work.
If the current behavior is intentional, then the documentation ought to be corrected.
This was previously reported in #54928 but was not fixed.
The text was updated successfully, but these errors were encountered: