cmd/cgo: goroutine freezes on stack overflow in C code #55919
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?(Also tested on
go version go1.18.3 darwin/amd64
)Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run the following
main.go
usingCGO_ENABLED=1 go run main.go
:What did you expect to see?
I expect the code to either print
bar
twice to the console or to crash with a stack overflow error.What did you see instead?
It prints
bar
once and hangs indefinitely.It appears that the goroutine that does not get scheduled on the main thread freezes (at 100% CPU utilization). This is just a guess, but it seems that the thread Go creates for the second goroutine gets a smaller stack size than the main thread, and that when it encounters a stack overflow, the error does not correctly propagate back to Go.
In terms of expected behaviour, I would expect cgo calls to show the same behaviour regardless of which goroutine they're called from. Failing that, I would expect that stack overflow errors in C code crash (not freeze) the process.
For context, we encountered this bug when using marcboeker/go-duckdb, which uses cgo to call DuckDB from Go. DuckDB can run into stack overflow errors on deeply nested queries. Crashes are fine in such cases, but silent freezes at 100% CPU utilization feel dangerous.
Let me know if there's any more information I can provide to help.
The text was updated successfully, but these errors were encountered: