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: lookupIPAddr mapErr causes panic #63927

Closed
lyouthzzz opened this issue Nov 3, 2023 · 6 comments
Closed

net: lookupIPAddr mapErr causes panic #63927

lyouthzzz opened this issue Nov 3, 2023 · 6 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@lyouthzzz
Copy link

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

$ go version
go1.18.10

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
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.18.10"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3128295910=/tmp/go-build -gno-record-gcc-switches"

What did you do?

parse dns domain when send http request

What did you expect to see?

no panic

What did you see instead?

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

 0  0x000000000046d1e1 in runtime.raise
    at /usr/local/go/src/runtime/sys_linux_amd64.s:168
 1  0x000000000044e8a5 in runtime.dieFromSignal
    at /usr/local/go/src/runtime/signal_unix.go:852
 2  0x000000000044f276 in runtime.sigfwdgo
    at /usr/local/go/src/runtime/signal_unix.go:1066
 3  0x000000000044d607 in runtime.sigtrampgo
    at /usr/local/go/src/runtime/signal_unix.go:430
 4  0x000000000046d1e1 in runtime.raise
    at /usr/local/go/src/runtime/sys_linux_amd64.s:167
 5  0x000000000044e8a5 in runtime.dieFromSignal
    at /usr/local/go/src/runtime/signal_unix.go:852
 6  0x0000000000438969 in runtime.crash
    at /usr/local/go/src/runtime/signal_unix.go:944
 7  0x0000000000438969 in runtime.fatalpanic
    at /usr/local/go/src/runtime/panic.go:1092
 8  0x0000000000438137 in runtime.gopanic
    at /usr/local/go/src/runtime/panic.go:941
 9  0x000000000044e77d in runtime.panicmem
    at /usr/local/go/src/runtime/panic.go:220
10  0x000000000044e77d in runtime.sigpanic
    at /usr/local/go/src/runtime/signal_unix.go:818
11  0x00000000005306b3 in net.(*Resolver).lookupIPAddr
    at /usr/local/go/src/net/lookup.go:344
12  0x000000000052d99a in net.(*Resolver).internetAddrList
    at /usr/local/go/src/net/ipsock.go:288
13  0x00000000005151bb in net.(*Resolver).resolveAddrList
    at /usr/local/go/src/net/dial.go:221
14  0x0000000000516128 in net.(*Dialer).DialContext
    at /usr/local/go/src/net/dial.go:406
15  0x000000000072b6db in net.(*Dialer).DialContext-fm
    at <autogenerated>:1
16  0x000000000071509a in net/http.(*Transport).dial
    at /usr/local/go/src/net/http/transport.go:1169
17  0x00000000007181bf in net/http.(*Transport).dialConn
    at /usr/local/go/src/net/http/transport.go:1607
18  0x0000000000716a50 in net/http.(*Transport).dialConnFor
    at /usr/local/go/src/net/http/transport.go:1449
19  0x000000000071696a in net/http.(*Transport).queueForDial.func1
    at /usr/local/go/src/net/http/transport.go:1418
20  0x000000000046b8a1 in runtime.goexit
    at /usr/local/go/src/runtime/asm_amd64.s:1571
@lyouthzzz
Copy link
Author

It's similar to this issue. #60029

@lyouthzzz
Copy link
Author

Ctx is done and then ctx.Error() returns nil. It's a random occurrence in our production environment. we use ip to avoid resolving domain,but this is not a long-term solution. we use custom context,but we can promise the context has no problem.

@bradfitz
Copy link
Contributor

bradfitz commented Nov 3, 2023

Ctx is done and then ctx.Error() returns nil. [...] we use custom context

That's not a valid implementation of context.Context. The interface docs say:

https://pkg.go.dev/context#Context

// If Done is closed, Err returns a non-nil error explaining why:

Therefore I don't think there's anything to fix on Go's side.

@bradfitz bradfitz closed this as completed Nov 3, 2023
@bradfitz
Copy link
Contributor

bradfitz commented Nov 3, 2023

Sorry, I hit the wrong button closing. Reopening. But I still don't know what we'd fix.

@bradfitz bradfitz reopened this Nov 3, 2023
@bcmills
Copy link
Contributor

bcmills commented Nov 3, 2023

On the one hand, mapErr could perhaps panic with a more helpful message in this case.

On the other hand, in general Go APIs do panic if the program violates invariants that are supposed to always hold in a correct program.

If you have a Context implementation that may close its Done channel but return nil from Err, that's not a valid implementation and it's likely to break way more than just the net package. Fundamentally you need to fix your Context implementation.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 3, 2023
@lyouthzzz
Copy link
Author

On the one hand, mapErr could perhaps panic with a more helpful message in this case.

On the other hand, in general Go APIs do panic if the program violates invariants that are supposed to always hold in a correct program.

If you have a Context implementation that may close its Done channel but return nil from Err, that's not a valid implementation and it's likely to break way more than just the net package. Fundamentally you need to fix your Context implementation.

Thank you for your patient reply. I will colse my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants