I had a weird crash in a program: fatal error: unexpected signal during runtime execution
This was when C code was being called that has worked a long time without problems.
Here is a fragment of the dump:
goroutine 1342 [syscall, locked to thread]:
runtime.cgocall(0x83d120, 0xc820654be8, 0x0)
/net/aps/64/opt/go/src/runtime/cgocall.go:123 +0x11b fp=0xc820654bb0 sp=0xc820654b80
main._Cfunc_makeGraph(0x7f7204001830, 0x0)
_/net/aistaff/kleiweg/paqu/src/pqserve/_obj/_cgo_gotypes.go:77 +0x3e fp=0xc820654be8 sp=0xc820654bb0
main.tree(0xc8200c68f0)
/net/aistaff/kleiweg/paqu/src/pqserve/tree.go:376 +0x1bba fp=0xc820655398 sp=0xc820654be8
And here another:
goroutine 1343 [runnable]:
net/http.(*response).Write(0xc82033c000, 0xc8204e6000, 0x79, 0xe0, 0x900000, 0x992c80, 0xc820415000)
/net/aps/64/opt/go/src/net/http/server.go:1208
fmt.Fprint(0x7f721cb93cb0, 0xc82033c000, 0xc820415060, 0x1, 0x1, 0x11, 0x0, 0x0)
/net/aps/64/opt/go/src/fmt/print.go:223 +0xa5
main.tree(0xc82033c410)
/net/aistaff/kleiweg/paqu/src/pqserve/tree.go:416 +0x2680
So, two goroutines are working executing code from tree.go, which calls C like this:
s1 := C.myfunc(C.CString(text))
s := C.GoString(s1)
C.free(unsafe.Pointer(s1))
The C string created by C.CString(text) is freed inside the C code of myfunc()
The C code in myfunc() may not be thread safe, but it is called in a single CGO call. Can Go do another C call when one is still running? I thought switching between goroutines didn't happen during execution of C code.
If this is the cause of the crash, a simple mutex will fix it, but this is such a rare thing that I can't test it.