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

net: Resolver does not appear to use its dialer function on Windows #33621

HouzuoGuo opened this issue Aug 13, 2019 · 2 comments

net: Resolver does not appear to use its dialer function on Windows #33621

HouzuoGuo opened this issue Aug 13, 2019 · 2 comments


Copy link

@HouzuoGuo HouzuoGuo commented Aug 13, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.7 windows/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\howard\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\howard\go
set GOROOT=c:\go
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\howard\AppData\Local\Temp\go-build943471142=/tmp/go-build -gno-record-gcc-switches

What did you do?

Run this code snippet

package main

import (

func main() {
	resolver := &net.Resolver{
		PreferGo:     true,
		StrictErrors: true,
		Dial: func(ctx context.Context, network, address string) (conn net.Conn, e error) {
	result, err := resolver.LookupHost(context.Background(), "")
	fmt.Println(result, err)

What did you expect to see?

A panic, as correctly demonstrated by running the snippet under Linux:

panic: nil

goroutine 6 [running]:
main.main.func1(0x53caa0, 0xc00007a300, 0x51a125, 0x3, 0xc0000183f0, 0xe, 0x42aedc, 0xc0000d6ad0, 0xc00007a310, 0xc000001b00)
        /home/howard/main.go:14 +0x29
net.(*Resolver).dial(0xc00000e0a0, 0x53caa0, 0xc00007a300, 0x51a125, 0x3, 0xc0000183f0, 0xe, 0xc0000125c0, 0x0, 0x0, ...)
        /home/howard/go/src/net/lookup_unix.go:67 +0x226
net.(*Resolver).exchange(0xc00000e0a0, 0x53ca60, 0xc0000180e0, 0xc0000183f0, 0xe, 0x632e656c676f6f67, 0x2e6d6f, 0x0, 0x0, 0x0, ...)
        /home/howard/go/src/net/dnsclient_unix.go:144 +0x280
net.(*Resolver).tryOneName(0xc00000e0a0, 0x53ca60, 0xc0000180e0, 0xc00009e140, 0xc000018630, 0xb, 0x1c, 0x0, 0x0, 0x0, ...)
        /home/howard/go/src/net/dnsclient_unix.go:244 +0x325
net.(*Resolver).goLookupIPCNAMEOrder.func1(0xc00000e0a0, 0x53ca60, 0xc0000180e0, 0xc00009e140, 0xc0000125a0, 0xc00007a2a0, 0x1c)
        /home/howard/go/src/net/dnsclient_unix.go:584 +0x90
created by net.(*Resolver).goLookupIPCNAMEOrder
        /home/howard/go/src/net/dnsclient_unix.go:583 +0x285
exit status 2

What did you see instead?

On Windows, the snippet never touched the dialer function and successfully resolves the domain name:

Copy link

@tmthrgd tmthrgd commented Aug 13, 2019

This is a duplicate of #29621, #33086 and #33097.

The net package docs currently say:

"On Windows, the resolver always uses C library functions, such as GetAddrInfo and DnsQuery."

@andybons andybons changed the title on Windows, net.Resolver does not appear to use its dailer function net: Resolver does not appear to use its dialer function on Windows Aug 13, 2019
@andybons andybons added this to the Unplanned milestone Aug 13, 2019
Copy link

@HouzuoGuo HouzuoGuo commented Aug 13, 2019

Thanks very much @tmthrgd. To help fellow users of Go, would it be better to note down the restriction in the doc of Dial function in addition to package description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants