Skip to content

runtime/race: sigsegv when using cgo callbacks with the race detector enabled #10874

@Thinkofname

Description

@Thinkofname

Only tested on linux/amd64. A simple way to reproduce this is to run the tests in misc/cgo/test
with the race detector enabled. It should crash as follows:

~/go/misc/cgo/test • GOTRACEBACK=2 go test -v -race
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x415885]

runtime stack:
runtime.throw(0x769db0, 0x2a)
    /home/matt/go/src/runtime/panic.go:527 +0x96 fp=0x7ffff9f37c10 sp=0x7ffff9f37bf8
runtime.sigpanic()
    /home/matt/go/src/runtime/sigpanic_unix.go:12 +0x5d fp=0x7ffff9f37c60 sp=0x7ffff9f37c10

goroutine 1 [syscall, locked to thread]:
runtime.cgocall_errno(0x4317f0, 0xc20804bef8, 0x0)
    /home/matt/go/src/runtime/cgocall.go:125 +0xc5 fp=0xc20804bed8 sp=0xc20804beb0
_/home/matt/go/misc/cgo/test._Cfunc_lockOSThreadC()
    ??:0 +0x56 fp=0xc20804bef8 sp=0xc20804bed8
_/home/matt/go/misc/cgo/test.init.1()
    /home/matt/go/misc/cgo/test/issue3775.go:23 +0x2d fp=0xc20804bf08 sp=0xc20804bef8
_/home/matt/go/misc/cgo/test.init()
    _/home/matt/go/misc/cgo/test/_test/_obj_test/_cgo_import.go:1 +0x1859 fp=0xc20804bf88 sp=0xc20804bf08
main.init()
    _/home/matt/go/misc/cgo/test/_test/_testmain.go:172 +0x9c fp=0xc20804bf98 sp=0xc20804bf88
runtime.main()
    /home/matt/go/src/runtime/proc.go:100 +0x220 fp=0xc20804bfe0 sp=0xc20804bf98
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc20804bfe8 sp=0xc20804bfe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc20803afe8 sp=0xc20803afe0

goroutine 2 [runnable]:
runtime.forcegchelper()
    /home/matt/go/src/runtime/proc.go:144 fp=0xc2080267e0 sp=0xc2080267d8
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc2080267e8 sp=0xc2080267e0
created by runtime.init.4
    /home/matt/go/src/runtime/proc.go:141 +0x32

goroutine 3 [GC sweep wait]:
runtime.gopark(0x78d008, 0x140b740, 0x719b50, 0xd, 0x44df14, 0x1)
    /home/matt/go/src/runtime/proc.go:185 +0x123 fp=0xc208026f68 sp=0xc208026f38
runtime.goparkunlock(0x140b740, 0x719b50, 0xd, 0x14, 0x1)
    /home/matt/go/src/runtime/proc.go:191 +0x5b fp=0xc208026fa0 sp=0xc208026f68
runtime.bgsweep(0xc208056000)
    /home/matt/go/src/runtime/mgcsweep.go:51 +0xba fp=0xc208026fd8 sp=0xc208026fa0
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc208026fe0 sp=0xc208026fd8
created by runtime.gcenable
    /home/matt/go/src/runtime/mgc.go:171 +0x5a

goroutine 4 [runnable]:
runtime.runfinq()
    /home/matt/go/src/runtime/mfinal.go:140 fp=0xc2080277e0 sp=0xc2080277d8
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc2080277e8 sp=0xc2080277e0
created by runtime.createfing
    /home/matt/go/src/runtime/mfinal.go:135 +0x67

goroutine 5 [runnable]:
os/signal.loop()
    /home/matt/go/src/os/signal/signal_unix.go:20 fp=0xc208027fe0 sp=0xc208027fd8
runtime.goexit()
    /home/matt/go/src/runtime/asm_amd64.s:1670 +0x1 fp=0xc208027fe8 sp=0xc208027fe0
created by os/signal.init.1
    /home/matt/go/src/os/signal/signal_unix.go:28 +0x4c
exit status 2
FAIL    _/home/matt/go/misc/cgo/test    0.008s

The common thing between the failing test and the issue with my own code seems to be callbacks from cgo into go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions