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: host lookup on Linux non-GNU-libc systems #33019
Comments
When using glibc the default when there is no /etc/nsswitch.conf is You can force the use of the C resolver by setting I'm not excited about doing a run-time test for whether we are using musl. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@ianlancetaylor
|
It seems like this issue was fixed in the meantime.
|
@mateusz834 Where did you find that quote? Thanks. |
@ianlancetaylor On the link you posted here: #33019 (comment) |
@mateusz834 Ah, thanks. Looks like this was changed in December, 2021 for https://sourceware.org/bugzilla/show_bug.cgi?id=28700. And it does seem that Go does the expected thing, so closing. Please comment if you disagree. |
@ianlancetaylor I'm unclear, sorry - I can see that glibc default behaviour has changed to match the muslc behaviour but has the golang net package also changed to match this behaviour? I can't see a reference to a PR above but it might just be whoever did the PR wasn't aware of this ticket. |
Gotcha. Looks like this was merged, which implements the change. |
Don't know if this is the same issue but on some of my systems, (mostly Arch Linux), net.LookupIP("localhost") don't give the IPv6 value (::1) only IPv4 (127.0.0.1).
but on the same machine, this Go code: https://go.dev/play/p/gHlxWsre2Cp
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Not tested on 1.12.7 but I don't believe any of the tickets included between 1.12.6 and 1.12.7 affect this issue.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The above program gives the wrong address for
localhost
if:localhost
.The system where this was observed is running Alpine Linux 3.9. This uses the musl libc. This libc does not support
/etc/nsswitch.conf
and so that file is usually missing.On this type of system, it seems that golang's name resolution code looks for
/etc/nsswitch.conf
, doesn't find it, and then defaults to DNS only, skipping any lookup in/etc/hosts
. The DNS query that is sent is not forlocalhost
but forlocalhost.x.y.z
wherex.y.z
is thedomain
setting fromresolv.conf
.If the configured DNS server produces a correct response for
localhost.x.y.z
then all is still well, but if it doesn't then lookup fails (or even worse, as below, returns an address for another host).My suggestion is that golang on musl libc systems should follow the musl libc convention, which is to check /etc/hosts first and then DNS.
A workaround is to add a file
/etc/nsswitch.conf
that specifieshosts: files dns
.What did you expect to see?
On a system with IPv6 enabled:
What did you see instead?
The exact output varies with the environment where it is run, but eg:
The text was updated successfully, but these errors were encountered: