Skip to content

net: Resolver leads to too many DNS queries #71712

Closed as not planned
Closed as not planned
@Shnitzelil

Description

@Shnitzelil

Go version

go.1.23.3 windows

Output of go env in your module/workspace:

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\<user>\AppData\Local\go-build
set GOENV=C:\Users\<user>\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\<user>\go\pkg\mod
set GONOPROXY=gitlab.otxlab.net
set GONOSUMDB=gitlab.otxlab.net
set GOOS=windows
set GOPATH=C:\Users\<user>\go
set GOPRIVATE=gitlab.otxlab.net
set GOPROXY=https://proxy.golang.org/cached-only
set GOROOT=C:\Users\<user>\go\pkg\mod\golang.org\t[email protected]
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\<user>\go\pkg\mod\golang.org\t[email protected]\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.3
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\<user>\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\scm\gitlab\<my project>\go.mod
set GOWORK=
set CGO_CFLAGS=-IC:/scm/ZMQ/include
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-LC:/scm/ZMQ/bin
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\<user>\AppData\Local\Temp\go-build2635385560=/tmp/go-build -gno-record-gcc-switches

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

package main

import (
	"fmt"
	"net"
	"net/http"
	"time"
)

func main() {
	// Create a custom dialer
	dialer := &net.Dialer{
		Timeout:   5 * time.Second, // Set timeout for dialing a connection
		KeepAlive: 30 * time.Second,
		FallbackDelay: time.Duration(-1), // Only IPv4
		Resolver: &net.Resolver{
			PreferGo: true,
		},
	}

	// Configure transport with the custom dialer
	transport := &http.Transport{
		DialContext:         dialer.DialContext,
		DisableKeepAlives:   false, // Keep connections alive
		MaxIdleConns:        10,
		IdleConnTimeout:     90 * time.Second,
		TLSHandshakeTimeout: 10 * time.Second,
	}

	// Create an HTTP client with the custom transport
	client := &http.Client{
		Transport: transport,
		Timeout:   10 * time.Second, // Overall request timeout
	}

	// Make a request using the custom client
	resp, err := client.Get("https://golang.org/")
	if err != nil {
		fmt.Println(err)
		return
	}
	
	_ = resp.Body.Close()
	resp, err = client.Get("http://golang.org/")
	if err != nil {
		fmt.Println(err)
		return
	}
	_ = resp.Body.Close()

}

What did you see happen?

Capture of Wireshark when PreferGo is set to True

Image

Capture of Wireshark when PreferGo is set to False
Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions