How to debug fatal error: unexpected signal during runtime execution ?

3,814 views
Skip to first unread message

Eric Z

unread,
Sep 15, 2014, 7:12:42 PM9/15/14
to golan...@googlegroups.com
Hello Golang-Nuts,

I am writing a go program calling c library and function. It works fluently in some cases, but sometime it exit with error code 2.

However the error printout starts with a long list of go routines at crash. This gives me no clue how to debug. Can some one give some advice? Thanks a lot.

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x0]
runtime stack:
runtime.throw(0x863885)
      /usr/local/go/src/pkg/runtime/panic.c:520 +0x69 fp=0x7fa2c0df9c28 sp=0x7fa2c0df9c10
 runtime: unexpected return pc for runtime.sigpanic called from 0x4098a5
 runtime.sigpanic()
    /usr/local/go/src/pkg/runtime/os_linux.c:222 +0x3d fp=0x7fa2c0df9c40 sp=0x7fa2c0df9c28



Cheers,
Eric

Andrew Gerrand

unread,
Sep 15, 2014, 7:20:16 PM9/15/14
to Eric Z, golang-nuts
You'll need to show more of the stacks. Usually the first stack trace is for the responsible goroutine.

Are you calling into multi-threaded C code? I've seen that cause this particular error.

Andrew

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Z

unread,
Sep 15, 2014, 7:28:28 PM9/15/14
to golan...@googlegroups.com, hadoo...@gmail.com

Thanks for taking a quick look.

The first goroutine looks like this. It still gives me no clue. It is a single thread c program. However, two go routines might be calling it at the same time.

goroutine 560 [syscall]:
runtime.cgocall(0x403820, 0x7fa2c01db918)
        /usr/local/go/src/pkg/runtime/cgocall.c:143 +0xe5 fp=0x7fa2c01db900 sp=0x7fa2c01db8b8
main._Cfunc_encoder(0x200000005, 0x64000000005, 0xcf22551000, 0xcf12d981c0, 0xca9b45f8fc, 0xcba710a8fc, 0x18)
        mycode/_obj/_cgo_defun.c:66 +0x36 fp=0x7fa2c01db918 sp=0x7fa2c01db900
main.encoder_core(0x7fa2c01dbe18, 0x1, 0x1, 0xca9b45f8fc, 0x22551000, 0x13b4df904, 0xcba710a8fc, 0xdbba000, 0x2f834904, 0xcd950dc020, ...)
        /home/eric.z/git/src/mycode/encoder.go:391 +0x2bc fp=0x7fa2c01dbaf0 sp=0x7fa2c01db918
main.encoder(0x6, 0xcd950ca5a0, 0xcd950dc020, 0x1, 0x1, 0x5, 0xcdc4cdc1d8, 0xc2080542a0, 0xcd94e81380, 0xcdc4cde300)
        /home/eric.z/git/src/mycode/encoder.go:460 +0xa7f fp=0x7fa2c01dbf58 sp=0x7fa2c01dbaf0
runtime.goexit()
        /usr/local/go/src/pkg/runtime/proc.c:1445 fp=0x7fa2c01dbf60 sp=0x7fa2c01dbf58
created by main.destination
        /home/eric.z/git/src/mycode/main.go:1493 +0x1243

Dave Cheney

unread,
Sep 15, 2014, 7:37:37 PM9/15/14
to golan...@googlegroups.com, hadoo...@gmail.com
Hi Eric,

Looks like there was a nil pointer dereference in your C code. Can you please make the _entire_ panic message available somewhere, possibly pastebin if you don't want to attach it here.

Dave

Eric Z

unread,
Sep 15, 2014, 7:54:01 PM9/15/14
to golan...@googlegroups.com, hadoo...@gmail.com

Thanks a million.

Here is the 3k line error track
http://pastebin.com/gNPE87kA

How did you tell it's a nil pointer dereference? It's pretty hard for me to understand the panic message. I am wondering if there's some tool to parse or blog post to teach on what to read.

Dave Cheney

unread,
Sep 15, 2014, 8:01:13 PM9/15/14
to Eric Z, golang-nuts
Code 0x0b is 11, which is SIGSEGV. addr=0x0, which is nil/null in most
programming languages.

main.encoder_core(0x7fa2c01dbe18, 0x1, 0x1, 0xca9b45f8fc, 0x22551000,
0x13b4df904, 0xcba710a8fc, 0xdbba000, 0x2f834904, 0xcd950dc020, ...)

What are the arguments to this function ?
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/65pdWIYga4E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Eric Z

unread,
Sep 15, 2014, 8:10:49 PM9/15/14
to golan...@googlegroups.com, hadoo...@gmail.com
Thank you Dave. This is very helpful. Let me add some code to check all pointers to be valid.

encoder_core calls the C function

func encoder_core(info []E2ASstruct, data []byte, coding []byte, e2as []chan E2ASstruct, disk_lock *sync.Mutex, page int, i_disk int, send_pending bool) bool

Dave Cheney

unread,
Sep 15, 2014, 8:22:51 PM9/15/14
to Eric Z, golang-nuts
Nothing obvious there, info is a slice of one value, data is a heap
allocated structure sliced out of a larger slice, the slice of
channels is odd, i'm not sure if the stack trace is showing the full
list of arguments to that function.

At this point all I can suggest is there is a bug in whatever code
you're calling via cgo.

Eric Z

unread,
Sep 16, 2014, 2:51:56 PM9/16/14
to golan...@googlegroups.com, hadoo...@gmail.com
Thanks Dave.

I am following your advice, and it does seem that the error comes from one the libraries the c code calls. It's sill pretty hard to track. Stack trace seems to be limited on indicating exactly which c code throws the error.

eviefe...@gmail.com

unread,
Aug 24, 2015, 8:40:22 PM8/24/15
to golang-nuts, hadoo...@gmail.com
hello!I got this problem in my program too ,do you konw how to solve this multi-threaded C code problem?

在 2014年9月16日星期二 UTC+8上午7:20:16,Andrew Gerrand写道:

Chaitanya Kapre

unread,
Sep 11, 2023, 8:12:08 AM9/11/23
to golang-nuts
Same issue found while doing multi threading in C. It runs fine when single thread is there but fails for multithread. Did you know how to implement multi threading in C python with golang integratiion?
Reply all
Reply to author
Forward
0 new messages