Skip to content

runtime.AddCleanup: Panic occurs when syscall.Close is called on macOS #70876

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
hxzhouh opened this issue Dec 17, 2024 · 2 comments
Closed

runtime.AddCleanup: Panic occurs when syscall.Close is called on macOS #70876

hxzhouh opened this issue Dec 17, 2024 · 2 comments

Comments

@hxzhouh
Copy link
Contributor

hxzhouh commented Dec 17, 2024

Go version

go version devel go1.24-1218566fe5 Mon Dec 16 18:19:39 2024 -0800 darwin/arm64

Output of go env in your module/workspace:

➜  AddCleanUp git:(main) ✗ go version
go version devel go1.24-1218566fe5 Mon Dec 16 18:19:39 2024 -0800 darwin/arm64
➜  AddCleanUp git:(main) ✗ gotip version 
go version devel go1.24-1218566 Mon Dec 16 18:19:39 2024 -0800 darwin/arm64

➜  AddCleanUp git:(main) ✗ go env 
AR='ar'
CC='clang'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/hxzhouh/Library/Caches/go-build'
GODEBUG=''
GOENV='/Users/hxzhouh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/ny/_2b7fvwx6v90sc44c8fbd0kr0000gn/T/go-build3735513723=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/hxzhouh/workspace/github/me/blog-example/go.mod'
GOMODCACHE='/Users/hxzhouh/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/hxzhouh/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/Users/hxzhouh/workspace/github/golang/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/hxzhouh/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/hxzhouh/workspace/github/golang/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.24-1218566fe5 Mon Dec 16 18:19:39 2024 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

source code:

  • This code will not report errors on the go.dev and Linux systems.
  • However, using the latest code and gossip on macOS will make it panic!
  • Removing syscall.Close(int(fd)) from AddCleanup will not report an error!
  • Calling syscall.read in AddCleanup doesn't give an error either!

What did you see happen?

please see the upload file
macos panic.txt
Please

What did you expect to see?

Don't Panic, Consistent with Linux

@ianlancetaylor
Copy link
Contributor

You are closing the file descriptor without calling the Close method of the File. This doesn't work. Don't try to mix and match syscall functions with os functions. In this case it is confusing the runtime network poller.

By the way, note that the os.File type already has a finalizer that will close the descriptor.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants