Skip to content

runtime/cgo: new pthread crash _cgo_try_pthread_create #68850

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
xuyinghao opened this issue Aug 13, 2024 · 9 comments
Closed

runtime/cgo: new pthread crash _cgo_try_pthread_create #68850

xuyinghao opened this issue Aug 13, 2024 · 9 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@xuyinghao
Copy link

xuyinghao commented Aug 13, 2024

Go version

go version go1.20.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="*"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="xxxx"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/data_disk/code/xyh/smartbench/go.mod"
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-build3335693688=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cgo call

glibc version

image

What did you see happen?

process crash

image

What did you expect to see?

This is a known issue of glibc. I hope go can fix it.
https://sourceware.org/bugzilla/show_bug.cgi?id=19951#c0

Workaround:

  1. Because the execution of sub-threads cannot be stopped, the recommended method is to set the thread status to detached (interface function pthread_attr_setdetachstate) when creating sub-threads. Do not use the pthread_detach interface in the main thread.

  2. You can call pthread_detach(pthread_self()) at the beginning of a subthread to set the detached state in the subthread.

@xuyinghao
Copy link
Author

image

@xuyinghao xuyinghao changed the title cgo new pthread crash cgo new pthread crash _cgo_try_pthread_create Aug 13, 2024
@seankhliao seankhliao changed the title cgo new pthread crash _cgo_try_pthread_create runtime/cgo: new pthread crash _cgo_try_pthread_create Aug 13, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 13, 2024
@ianlancetaylor
Copy link
Member

For text, please use plain text, not images. Plain text is much easier to read. Thanks.

@ianlancetaylor
Copy link
Member

If I understand the glibc bug correctly, it only occurs after some thread has exited. That is unusual in Go programs, in which threads typically never exit after they have been created. Can you confirm that in your program some threads exit? Thanks.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/605257 mentions this issue: runtime/cgo: create C pthreads in detached state

@And-ZJ
Copy link
Contributor

And-ZJ commented Sep 6, 2024

Hello, excuse me, I'd like to ask, this question seems to exist in the lower version also, do you have a backport plan?

@ianlancetaylor
Copy link
Member

@And-ZJ Although the change made sense by itself, I haven't seen any confirmation that it actually fixes a problem for anybody. Do you have a test case where this change makes a difference?

@xuyinghao
Copy link
Author

When will the release package be released to fix this problem? @ianlancetaylor

@ianlancetaylor
Copy link
Member

@xuyinghao The change will be in the 1.24 release, which is scheduled for February, 2025.

We can probably backport the change to minor releases of 1.22 or 1.23, but as noted above we haven't seen a test case where it actually makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

5 participants