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

proposal: net: only request DNS A record when IPv6 not support, when using the net.Dial method #58995

Open
WeiZhixiong opened this issue Mar 12, 2023 · 2 comments · May be fixed by #58997
Open
Labels
Milestone

Comments

@WeiZhixiong
Copy link

Problem:

when use net or net/http start reqeust to domain name, like this:

http.Get("https://golang.org/")
net.Dial("tcp", "golang.org:80")
net.Dial("udp", "golang.org:443")

The method DialContext of net.Dialer will resolve both A and AAAA records for a domain name, regardless of whether the machine's network supports IPv6 or not. If not support IPv6, DNS AAAA requests is unnecessary, it will cause additional cost.

Possible solution:
change file: go/src/net/dial.go
old:

func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn, error) {
        ...
	addrs, err := d.resolver().resolveAddrList(resolveCtx, "dial", network, address, d.LocalAddr)
        ...
}

new:

func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn, error) {
         ...
	networkForResolve := network
	switch network {
	case "tcp", "udp":
		if !supportsIPv6() {
			networkForResolve = network + "4"
		}
	}
	addrs, err := d.resolver().resolveAddrList(resolveCtx, "dial", networkForResolve, address, d.LocalAddr)
        ...
}
@seankhliao
Copy link
Member

what additional cost are we talking about?
it should fail ~immediately if ipv6 isn't available

@WeiZhixiong
Copy link
Author

what additional cost are we talking about? it should fail ~immediately if ipv6 isn't available

before send real request, domain name need be resolve to IP, If not support IPv6, domain name AAAA records is unnecessary, DNS AAAA requests cause additional cost.
this blog has good explanation about additional cost: https://studygolang.com/topics/15021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
3 participants