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

Closed
HouzuoGuo opened this issue Aug 13, 2019 · 3 comments
Closed

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

HouzuoGuo opened this issue Aug 13, 2019 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@HouzuoGuo
Copy link

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?

Yes

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 GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\howard\go
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-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 (
	"context"
	"fmt"
	"net"
)

func main() {
	resolver := &net.Resolver{
		PreferGo:     true,
		StrictErrors: true,
		Dial: func(ctx context.Context, network, address string) (conn net.Conn, e error) {
			panic(nil)
		},
	}
	result, err := resolver.LookupHost(context.Background(), "google.com")
	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:

[216.58.207.206] 
@tmthrgd
Copy link
Contributor

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 NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Aug 13, 2019
@andybons andybons added this to the Unplanned milestone Aug 13, 2019
@HouzuoGuo
Copy link
Author

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?

@bradfitz
Copy link
Contributor

Closing as a dup of #33097. (and #29621, #33086, as @tmthrgd pointed out).

#33097 has a pending approved fix and is about to be submitted. For people finding this in the future, the fix should be in Go 1.19. (Check the release notes when it comes out.)

@golang golang locked and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants