-
Notifications
You must be signed in to change notification settings - Fork 18k
net: Resolver leads to too many DNS queries #71712
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
Comments
CC @ianlancetaylor, @neild. |
I see 4 requests no matter the selected resolver: $ GODEBUG=netdns=cgo+2 go run .
go package net: confVal.netCgo = true netGo = false
go package net: GODEBUG setting forcing use of the cgo resolver
go package net: hostLookupOrder(golang.org) = cgo
go package net: hostLookupOrder(go.dev) = cgo
go package net: hostLookupOrder(golang.org) = cgo
go package net: hostLookupOrder(go.dev) = cgo
$ GODEBUG=netdns=go+2 go run .
go package net: confVal.netCgo = false netGo = true
go package net: GODEBUG setting forcing use of the Go resolver
go package net: hostLookupOrder(golang.org) = files,dns
go package net: hostLookupOrder(go.dev) = files,dns
go package net: hostLookupOrder(golang.org) = files,dns
go package net: hostLookupOrder(go.dev) = files,dns EDIT: note that this requires |
I believe 4 requests is expected: the test uses http.Get, which follow redirects, so there's:
go itself does not cache DNS queries, it relies on the host to do so, see #24796 closing as working as intended. |
Also if the DNS requests were concurrent, we would only do one of them, as we use singleflight. |
It should happen only one time to each domain/hostname... |
Please re-test it on Windows. |
As noted above, Go expects the DNS resolver to do caching. The Go standard library does not cache DNS results itself. That is not its job.
You can show us the output on Windows by setting the environment variable yourself. |
I expect there to be the same result, i guess that windows does some internal caching, thus we do not see additional requests in cgo resolver (but we still call to the OS do to the hostname lookup). |
Go version
go.1.23.3 windows
Output of
go env
in your module/workspace:What did you do?
Set http client enabling Go DNS resolver lead to too many queries.
2 for HTTPS and another 2 for HTTP.
By using OS DNS resolving I see only 1 request
This is the code
What did you see happen?
Capture of Wireshark when PreferGo is set to True
Capture of Wireshark when PreferGo is set to False

What did you expect to see?
To see only one for HTTP and HTTPS not duplicate queries.
Also if I understand correctly setting FallbackDelay: time.Duration(-1) should enable IPv4 only.
The text was updated successfully, but these errors were encountered: