Skip to content

net: nil *Resolver not equivalent to zero resolver, despite doc #24330

Closed
@philpennock

Description

@philpennock

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

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pdp/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pdp/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vs/7q9nz5955_z7b7zxfz437zrm0000gn/T/go-build515078480=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tested the assertion at https://golang.org/pkg/net/#Resolver that:

A nil *Resolver is equivalent to a zero Resolver.

https://play.golang.com/p/B40hcxy_Uuu

In the Go sandbox, it errors out because of the network restrictions. Run locally, this panics:

panic: runtime error: invalid memory address or nil pointer dereference

Swap the commenting-out of the r declaration to create a zero resolver, and the code runs perfectly.

What did you expect to see?

No difference in output between the two ways of declaring the resolver, because the documentation explicitly asserts the behavior of a nil *Resolver.

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10bedd6]

goroutine 5 [running]:
net.(*Resolver).lookupIP(0x0, 0x112e2e0, 0xc4200180f0, 0x1119095, 0xe, 0x0, 0xc420001b00, 0xc420062040, 0x0, 0x0)
	/usr/local/go/src/net/lookup_unix.go:90 +0x26
net.(*Resolver).(net.lookupIP)-fm(0x112e2e0, 0xc4200180f0, 0x1119095, 0xe, 0x1028169, 0x8, 0xc420062040, 0x0, 0xc420035ea0)
	/usr/local/go/src/net/lookup.go:192 +0x56
net.glob..func10(0x112e2e0, 0xc4200180f0, 0xc420010370, 0x1119095, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/net/hook.go:19 +0x52
net.(*Resolver).LookupIPAddr.func1(0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/net/lookup.go:200 +0xd8
internal/singleflight.(*Group).doCall(0x11bbdf0, 0xc42009e0f0, 0x1119095, 0xe, 0xc420090510)
	/usr/local/go/src/internal/singleflight/singleflight.go:95 +0x2e
created by internal/singleflight.(*Group).DoChan
	/usr/local/go/src/internal/singleflight/singleflight.go:88 +0x2d0
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions