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: panic on LookupHost when running in a libOS #59242

Closed
thomasten opened this issue Mar 25, 2023 · 3 comments
Closed

net: panic on LookupHost when running in a libOS #59242

thomasten opened this issue Mar 25, 2023 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@thomasten
Copy link

I'm not sure whether this can be considered a bug in Go, but let me explain. In my environment, rlim_max for RLIMIT_NOFILE is RLIM_INFINITY. This causes an overflow here:

go/src/net/lookup_unix.go

Lines 148 to 151 in aee9a19

if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
return 500
}
r := int(rlim.Cur)

(rlim_cur has been set to rlimt_max here:

go/src/os/rlimit.go

Lines 27 to 30 in aee9a19

if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max {
lim.Cur = lim.Max
adjustFileLimit(&lim)
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
)

As far as I could find out, on Linux it's not possible to set RLIMIT_NOFILE to anything greater than 0x7FFF_FFFF. So the overflow can't happen. I couldn't find out whether this is true for all Unix/POSIX systems supported by Go.

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

$ go version
go version go1.20.2 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tho/.cache/go-build"
GOENV="/home/tho/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tho/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tho/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4248147521=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run this on a system/libOS where rlim_max for RLIMIT_NOFILE is RLIM_INFINITY and force cgo lookup (e.g., with env var RES_OPTIONS=rotate):

func main() {
	fmt.Println(net.LookupHost("localhost"))
}

What did you expect to see?

[127.0.0.1] <nil>

What did you see instead?

panic: makechan: size out of range

goroutine 1 [running]:
net.acquireThread.func1()
        net/net.go:690 +0x28
sync.(*Once).doSlow(0x680?, 0x4e3280?)
        sync/once.go:74 +0xc2
sync.(*Once).Do(...)
        sync/once.go:65
net.acquireThread()
        net/net.go:689 +0x31
net.cgoLookupIPCNAME({0x4f0a1e, 0x2}, {0x4f170d, 0x9})
        net/cgo_unix.go:136 +0x85
net.cgoLookupIP({0x516ff0, 0xc00001c098}, {0x4f0a1e, 0x2}, {0x4f170d, 0x9})
        net/cgo_unix.go:216 +0x2fa
net.cgoLookupHost({0x516ff0?, 0xc00001c098?}, {0x4f170d?, 0x9?})
        net/cgo_unix.go:49 +0x55
net.(*Resolver).lookupHost(0x5b44c0, {0x516ff0, 0xc00001c098}, {0x4f170d, 0x9})
        net/lookup_unix.go:59 +0xad
net.(*Resolver).LookupHost(0xc0000061a0?, {0x516ff0, 0xc00001c098}, {0x4f170d, 0x9})
        net/lookup.go:191 +0x15c
net.LookupHost(...)
        net/lookup.go:177
main.main()
        ./main.go:9 +0x3e
@ianlancetaylor
Copy link
Contributor

Thanks. Does https://go.dev/cl/479436 fix the problem?

@gopherbot
Copy link

Change https://go.dev/cl/479436 mentions this issue: net: don't assume that NOFILE rlimit fits in an int

@thomasten
Copy link
Author

Thanks for your quick response. Yes, just tested it and your CL fixes the problem.

@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 27, 2023
@mdempsky mdempsky added this to the Go1.21 milestone Mar 27, 2023
johanbrandhorst pushed a commit to Pryz/go that referenced this issue Mar 28, 2023
No test because a test requires a system on which we can set RLIMIT_NOFILE
to RLIM_INFINITY, which we normally can't.

Fixes golang#59242

Change-Id: I8fc30e4206bb2be46369b5342360de556ce75a96
Reviewed-on: https://go-review.googlesource.com/c/go/+/479436
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants