Skip to content
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: LookupHost returns "no such host" when dns request timeout #10417

Closed
ashi009 opened this issue Apr 10, 2015 · 4 comments
Closed

net: LookupHost returns "no such host" when dns request timeout #10417

ashi009 opened this issue Apr 10, 2015 · 4 comments

Comments

@ashi009
Copy link

ashi009 commented Apr 10, 2015

What version of Go are you using (go version)?

go version go1.4.2 linux/amd64

What operating system and processor architecture are you using?

Ubuntu 14.04.1 LTS

What did you do?

net.LookupHost("1428707955.plus.google.com.")

In this case DNS resolver doesn't response to queries.

What did you expect to see?

Timeout error

What did you see instead?

lookup 1428707955.plus.google.com.: no such host
timeout: false

How to reproduce the problem?

The test conducted uses an iptables rule to drop all inbound DNS responses. And the host used for the test "X.plus.google.com" (X = a timestamp) has a wildcard DNS record, so it should exist regardless what "X" is.

Test code and log is available at:
https://gist.github.com/ashi009/b97db1606258385cc32d

$ sudo apt-get install ngrep
$ git clone https://gist.github.com/b97db1606258385cc32d.git
$ cd b97db1606258385cc32d
$ chmod +x reproduce.sh
$ ./reproduce.sh

Note that, this error is also reproducible on go version go1.4.2 darwin/amd64, but needs different setup as iptables, strace are not available on mac.

@ianlancetaylor
Copy link
Contributor

What is the exact message when you print out the error?

@ashi009
Copy link
Author

ashi009 commented Apr 11, 2015

@ianlancetaylor Updated.

@ianlancetaylor
Copy link
Contributor

By default, unless you did something unusual when you built the Go compiler, the Go DNS client simply calls the system function getaddrinfo in this case. That error means that getaddrinfo returned EAI_NONAME. That is usually displayed as "Name or service not known" but to make the different DNS implementations more compatible the Go library converts it to "no such host".

Unfortunately, as far as I can see, the getaddrinfo function has no way to indicate a timeout or a failure to contact the DNS servers. When using the native Go DNS client, it is possible to get a timeout error. When calling getaddrinfo, which is the default, that is not possible.

If you build your own Go distribution, you can force use of the native Go DNS client rather than getaddrinfo by building your program with "go build -tags netgo -installsuffix netgo". But I don't see any way to fix this with the default build.

@ashi009
Copy link
Author

ashi009 commented Apr 11, 2015

I see. But would you mind to document that in net package?

@mikioh mikioh changed the title net.LookupHost() returns "no such host" when dns request timeout net: LookupHost returns "no such host" when dns request timeout Apr 12, 2015
ianlancetaylor added a commit that referenced this issue Apr 13, 2015
Update #10417.

Change-Id: Ibfbdd05358f696a37217eef160f71b14a468ff86
Reviewed-on: https://go-review.googlesource.com/8788
Reviewed-by: Rob Pike <r@golang.org>
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants