Skip to content

runtime: kevent on fd 0 failed with 9 fatal error: runtime: netpoll failed #48310

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

Closed
ericlagergren opened this issue Sep 10, 2021 · 8 comments
Closed

Comments

@ericlagergren
Copy link
Contributor

ericlagergren commented Sep 10, 2021

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

$ go version
go version go1.17 darwin/arm64

Does this issue reproduce with the latest release?

Yes, also reproduced it with Go 1.17.1.

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

$ uname -a
Darwin Erics-MacBook-Air.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 arm64
go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN="/Users/eric/gopath/bin"
GOCACHE="/Users/eric/Library/Caches/go-build"
GOENV="/Users/eric/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/eric/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/eric/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/eric/git/lwcrypto/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2f/2_yz21b92h94_pvr2m00gzh80000gn/T/go-build2146294539=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was benchmarking some C code to compare it against existing Go code. I haven't had a chance to try and get a working minimal repro yet, but: https://play.golang.org/p/GBK19-dOhsv

What did you expect to see?

Anything other than a crash.

What did you see instead?

A crash.

$ go test -v -vet all -failfast -bench .
=== RUN   TestVectors128a
runtime: kevent on fd 0 failed with 9
fatal error: runtime: netpoll failed

runtime stack:
runtime.throw({0x100faa6f7, 0x17})
	/usr/local/go/src/runtime/panic.go:1198 +0x54
runtime.netpoll(0x8bb2c8de54)
	/usr/local/go/src/runtime/netpoll_kqueue.go:132 +0x378
runtime.findrunnable()
	/usr/local/go/src/runtime/proc.go:2947 +0x72c
runtime.schedule()
	/usr/local/go/src/runtime/proc.go:3367 +0x27c
runtime.park_m(0x14000001520)
	/usr/local/go/src/runtime/proc.go:3516 +0x188
runtime.mcall()
	/usr/local/go/src/runtime/asm_arm64.s:179 +0x54

goroutine 1 [chan receive]:
testing.(*T).Run(0x14000087040, {0x100fa8548, 0xf}, 0x100ff9a28)
	/usr/local/go/src/testing/testing.go:1307 +0x344
testing.runTests.func1(0x14000087040)
	/usr/local/go/src/testing/testing.go:1598 +0x80
testing.tRunner(0x14000087040, 0x140000b3d18)
	/usr/local/go/src/testing/testing.go:1259 +0x104
testing.runTests(0x140000ac030, {0x1010a57b0, 0x1, 0x1}, {0xc046da4720722ae8, 0x8bb2d2ade4, 0x1010ad680})
	/usr/local/go/src/testing/testing.go:1596 +0x3ec
testing.(*M).Run(0x140000ce000)
	/usr/local/go/src/testing/testing.go:1504 +0x4fc
main.main()
	_testmain.go:51 +0x17c

goroutine 19 [runnable]:
strconv.genericFtoa({0x1400009b588, 0x1, 0x44}, 0x3f11e42e12620254, 0x66, 0x2, 0x40)
	/usr/local/go/src/strconv/ftoa.go:57
strconv.AppendFloat(...)
	/usr/local/go/src/strconv/ftoa.go:54
fmt.(*fmt).fmtFloat(0x1400009b560, 0x3f11e42e12620254, 0x40, 0x66, 0x6)
	/usr/local/go/src/fmt/format.go:496 +0x78
fmt.(*pp).fmtFloat(0x1400009b520, 0x3f11e42e12620254, 0x40, 0x66)
	/usr/local/go/src/fmt/print.go:408 +0xd4
fmt.(*pp).printArg(0x1400009b520, {0x100fdb5e0, 0x140000a2088}, 0x66)
	/usr/local/go/src/fmt/print.go:666 +0x25c
fmt.(*pp).doPrintf(0x1400009b520, {0x100fa671d, 0x5}, {0x14000050dc8, 0x1, 0x1})
	/usr/local/go/src/fmt/print.go:1122 +0x798
fmt.Sprintf({0x100fa671d, 0x5}, {0x14000050dc8, 0x1, 0x1})
	/usr/local/go/src/fmt/print.go:219 +0x54
testing.fmtDuration(0x10a9a)
	/usr/local/go/src/testing/testing.go:632 +0xb0
testing.(*T).report(0x140000871e0)
	/usr/local/go/src/testing/testing.go:1525 +0x34
testing.tRunner.func1(0x140000871e0)
	/usr/local/go/src/testing/testing.go:1242 +0x31c
testing.tRunner(0x140000871e0, 0x100ff9a28)
	/usr/local/go/src/testing/testing.go:1265 +0x148
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1306 +0x328
exit status 2
FAIL	github.com/ericlagergren/lwcrypto/ascon/ctest	0.169s
@ericlagergren
Copy link
Contributor Author

ericlagergren commented Sep 10, 2021

For some reason, the call to Scan in readVecs always returns false. Moving vectors_128a.txt into the current directory (or ./testdata/, etc.) doesn't change anything.

Identical code that does not use cgo does not crash.

The code runs clean with -race.

@thanm
Copy link
Contributor

thanm commented Sep 10, 2021

@ericlagergren thanks for the report. Would you kindly update your example so that it is buildable/runnable?

@ianlancetaylor
Copy link
Member

Error 9 is EBADF. The error message reporting fd 0 is weird. That suggests that the program is being invoked with standard input closed. I don't see how that could happen. Still, it should work. My first guess, without looking at the code at all, is that something in the C code is doing a dup2 to put something at descriptor 0, not realizing that that is closing the kqueue descriptor. Or, something in the C code is zeroing out memory such that the runtime variable is being clobbered to 0.

@ericlagergren
Copy link
Contributor Author

@thanm yeah, I've uploaded it here: https://github.com/ericlagergren/lwcrypto/tree/issue48310

git clone https://github.com/ericlagergren/lwcrypto.git
git checkout issue48310
cd ascon/ctest
go test -v

@ericlagergren
Copy link
Contributor Author

@ianlancetaylor the C code does not call dup2. It also isn't even running by the time the crash happens.

@ericlagergren
Copy link
Contributor Author

ericlagergren commented Sep 10, 2021

Can repro with Go 1.16.7. Can't test with Go 1.15.x because there isn't a darwin/arm64 binary release for Go 1.15.x.

@ericlagergren
Copy link
Contributor Author

ericlagergren commented Sep 10, 2021

Oh. You know what it is? I have a C function named open. Different signature, but same name as open(2). Changing the name fixes the problem.

@ianlancetaylor
Copy link
Member

Great, thanks for following up.

@golang golang locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants