Closed as not planned
Description
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
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.