Skip to content

net: DNS resolver use both A and AAAA queries if only tcp4 network use #71281

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

Closed
VovkoO opened this issue Jan 15, 2025 · 14 comments
Closed

net: DNS resolver use both A and AAAA queries if only tcp4 network use #71281

VovkoO opened this issue Jan 15, 2025 · 14 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@VovkoO
Copy link

VovkoO commented Jan 15, 2025

Go version

go1.23.4

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/vladimir/Library/Caches/go-build'
GOENV='/Users/vladimir/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/vladimir/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/vladimir/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/vladimir/go/go1.23.4'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/vladimir/go/go1.23.4/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/vladimir/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/vladimir/go/src/tests/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/81/t0n_z8cd16q83h4w7fg9ml9r0000gp/T/go-build2923957466=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Hello, I'm trying to get dns resolver in grpc to use only A queries, instead of using both A and AAAA. It use method LookupHost from dns resolver:
https://github.com/golang/go/blob/master/src/net/lookup_unix.go#L55
Which uses either "cgoLookupHost" or "goLookupHostOrder" method, depending on the chosen resolver. But in both of them, the use of "ip" in the network argument is hardcoded, which leads to the use of both ipv4 and ip6 as I understand it.
So, Is this behavior correct and can it be used only "A" dns queries?

What did you see happen?

Both A and AAAA dns queries use.

What did you expect to see?

Only A dns queries use if tcp4 usage is explicitly specified

@mateusz834
Copy link
Member

mateusz834 commented Jan 15, 2025

You can try Resolver.LookupNetIP, there you can pass the network as a parameter. Not sure whether there is anything that we can do here.

@seankhliao
Copy link
Member

I think it's up to the caller to provide an appropriate Dial function to Resolver.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@ianlancetaylor
Copy link
Contributor

I'm not sure that's right. See #45024.

@mateusz834
Copy link
Member

@ianlancetaylor can you explain further? 53dd0d7

@seankhliao
Copy link
Member

#45024 makes Dial aware of the network, but this report sounds like grpc's equivalent of Dial indiscriminately uses LookupHost without passing any way of letting Resolver know what network it should restrict the results to.

@mknyszek mknyszek changed the title DNS resolver use both A and AAAA queries if only tcp4 network use net: DNS resolver use both A and AAAA queries if only tcp4 network use Jan 15, 2025
@mknyszek mknyszek added this to the Backlog milestone Jan 15, 2025
@mknyszek
Copy link
Contributor

CC @neild

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 15, 2025
@ianlancetaylor
Copy link
Contributor

@mateusz834 What I mean is: the described behavior sounds like something we have fixed in the past. I don't know if there is a real bug here.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 15, 2025
@mateusz834
Copy link
Member

mateusz834 commented Jan 15, 2025

The bug report mentions LookupHost, which does not accept the the network parameter, thus i think that this behaviour is fine.

@VovkoO

I don`t understand this:

Only A dns queries use if tcp4 usage is explicitly specified

Where the "tcp4" is explicitly specified? You mention that it uses LookupHost, which uses "ip".

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 15, 2025
@VovkoO
Copy link
Author

VovkoO commented Jan 16, 2025

I think I misunderstood something last time. I assumed that if I created an GRPC connection with a custom dialer that explicitly specified the use of tcp4, then the DNS resolver would also take this information into account.

conn, err := grpc.DialContext(ctx, "",
    grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
    return (&net.Dialer{}).DialContext(ctx, "tcp4", addr)
    }),
)

But it looks like these are two independent parts and grpc resolver always use LookupHost.
https://github.com/grpc/grpc-go/blob/master/internal/resolver/dns/dns_resolver.go#L319

@seankhliao
Copy link
Member

yes grpc has its own pluggable resolver setup

@seankhliao
Copy link
Member

I'm going to close this as it's a gRPC issue, see https://grpc.io/docs/guides/custom-name-resolution/

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
@ianlancetaylor
Copy link
Contributor

Thanks.

@VovkoO
Copy link
Author

VovkoO commented Jan 17, 2025

Ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants