Skip to content

runtime: Uncaught panics in callbacks from foreign threads result in SIGSEGV #5657

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
eliasnaur opened this issue Jun 6, 2013 · 6 comments
Closed

Comments

@eliasnaur
Copy link
Contributor

The attached test case crashes when a foreign thread makes a Go callback that panics.

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

What steps will reproduce the problem?
1. Run attached test case with go test

What is the expected output?
A nice message and stack trace just as for normal uncaught panics.

What do you see instead?
SIGSEGV: segmentation violation
PC=0x421d1d

signal: segmentation fault (core dumped)

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Ubunt 13.04 amd64

Which version are you using?  (run 'go version')
go version devel +1c764773c6ce Tue Jun 04 08:33:00 2013 +0200 linux/amd64

Attachments:

  1. thread-callback-panic.tar.bz2 (481 bytes)
@minux
Copy link
Member

minux commented Jun 9, 2013

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jun 10, 2013

Comment 2:

It's not a panic. If it's in non-Go code, it's a SIGSEGV.
There's very little we can do safely in this context.

Status changed to Unfortunate.

@dvyukov
Copy link
Member

dvyukov commented Jun 10, 2013

Comment 3:

From the description it looks like it talks about *Go* code in a callback on external
thread.

@minux
Copy link
Member

minux commented Jun 10, 2013

Comment 4:

right. it's about panic in Go callback functions, the following is a simpler reproducer:
// callback.go
package main
// void runThread(void);
import "C"
//export Callback
func Callback() {
    panic("callback panic")
}
func main() {
    C.runThread()
    select {}
}
// callback.c
#include <pthread.h>
#include "_cgo_export.h"
void *thread_main(void *unused) {
    Callback();
}
void runThread() {
    pthread_t p;
    pthread_create(&p, NULL, thread_main, NULL);
    pthread_join(p, 0);
}
Output:
$ ./test-panic 
SIGSEGV: segmentation violation
PC=0x1be6d

@rsc
Copy link
Contributor

rsc commented Jun 10, 2013

Comment 5:

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 6:

g% ./callback
SIGSEGV: segmentation violation
PC=0x401c2dd
runtime.lessstack()
    /Users/rsc/g/go/src/pkg/runtime/asm_amd64.s:289 +0x1d
goroutine 3 [running]:
reflect.call(0x4059438, 0x421ef68)
    /Users/rsc/g/go/src/pkg/runtime/asm_amd64.s:235 fp=0x421ee58
runtime.panic(0x4021dc0, 0xc21000a010)
    /Users/rsc/g/go/src/pkg/runtime/panic.c:234 +0x51 fp=0x421ee98
main.Callback()
    /tmp/callback/x.go:9 +0x55 fp=0x421eec8
----- stack segment boundary -----
runtime.panic(0x4021dc0, 0xc21000a010)
    /Users/rsc/g/go/src/pkg/runtime/panic.c:247 +0x106 fp=0x421ee98
main.Callback()
    /tmp/callback/x.go:9 +0x55 fp=0x421eec8
----- stack segment boundary -----
runtime.cgocallbackg1()
    /Users/rsc/g/go/src/pkg/runtime/cgocall.c:311 +0xbf fp=0x421ef80
runtime.cgocallbackg()
    /Users/rsc/g/go/src/pkg/runtime/cgocall.c:281 +0x84 fp=0x421ef90
runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
    /Users/rsc/g/go/src/pkg/runtime/asm_amd64.s:620 +0x67 fp=0x421efa0
runtime.goexit()
    /Users/rsc/g/go/src/pkg/runtime/proc.c:1332 fp=0x421efa8
goroutine 1 [syscall]:
main._Cfunc_runThread(0x4010ed3)
    _/tmp/callback/_obj/_cgo_defun.c:43 +0x31
main.main()
    /tmp/callback/x.go:11 +0x1a
goroutine 4 [syscall]:
runtime.goexit()
    /Users/rsc/g/go/src/pkg/runtime/proc.c:1332
rax     0xc2100016c0
rbx     0xc210012800
rcx     0x0
rdx     0x4059438
rdi     0xb0103e00
rsi     0xc210012840
rbp     0xc2100016c0
rsp     0x0
r8      0x421e000
r9      0x0
r10     0x21ec3fd6
r11     0x66a2222a
r12     0x2f83c0f0befae
r13     0x2fa72c37b97f0
r14     0x1315b87c3ec35a00
r15     0x4000f20
rip     0x401c2dd
rflags  0x10216
cs      0x2b
fs      0x0
gs      0x0
g%

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants