Skip to content
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

cmd/cgo: misleading report on crash in cgo code #3797

Closed
dvyukov opened this issue Jul 4, 2012 · 7 comments

Comments

@dvyukov
Copy link
Member

commented Jul 4, 2012

SIGSEGV in cgo-wrapped mysql produces the following report which is completely
misleading:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x7fc8c17948c2]
goroutine 1 [chan receive]:
net.(*pollServer).WaitRead(0xf840143c80, 0xf8401486c0, 0xf8400d5c30,
0xb, 0xf8400d5c01, ...)
        /usr/local/google/home/msolomon/dev/go/src/pkg/net/fd.go:268 +0x73
net.(*netFD).accept(0xf8401486c0, 0x504ed0, 0x0, 0xf84009c210,
0xf8400aa040, ...)

gdb reveals the real cause:

(gdb) bt
#0  my_stat (path=0x7f38aa7fac50 "vt-mysql/share/mysql/charsets/Index.xml",
stat_area=0x7f38aa7fab90, my_flags=0)
   at my_lib.c:540
#1  0x00007f38c4dea70f in my_read_charset_file (filename=0x2 <Address 0x2 out of
bounds>, myflags=0) at charset.c:338
#2  0x00007f38c4deb51e in init_available_charsets () at charset.c:431
#3  0x00007f38c540e400 in pthread_once () at
../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S:104
#4  0x00007f38c4deb144 in get_charset_by_csname (cs_name=0x7f3890006ff0
"utf8", cs_flags=32, flags=-1434465744) at charset.c:572
#5  0x00007f38c4dfdc46 in mysql_init_character_set (mysql=0x7f38900009e0) at
client.c:1807
#6  0x00007f38c4dff8ed in mysql_real_connect (mysql=0x7f38900009e0, host=0x7f38c4e03fb0
"localhost", user=0x7f38900008c0 "vt_dba", 
   passwd=<optimized out>, db=0x0, port=<optimized out>, unix_socket=0x7f38900008e0 "/vt/vt_0000041983/mysql.sock", client_flag=0) at client.c:2224
#7  0x0000000000527e05 in _cgo_a45dcd6e4066_Cfunc_mysql_real_connect ()

I can understand if Go can't unwind C stack, but at least it can show the correct
goroutine that executes cgo call and show status [cgo call].

Mike may provide more details.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 1:

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

Status changed to Accepted.

@dvyukov

This comment has been minimized.

Copy link
Member Author

commented Sep 12, 2012

Comment 2:

This is something we actually spent several hours debugging.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 3:

Labels changed: added go1.1.

@msolo

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 4:

The original problem was the my_* calls rely on thread-local state to be initialized. I
was not pedantically initializing this thread-local state and a goroutine migrating
across threads was leading to this crash.
I now pedantically initialize the thread locals in every cgo calls with a special set of
wrappers.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2012

Comment 5:

I am in no way trying to say this bug is unimportant. In fact it is tagged for fixing in
Go1.1.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2012

Comment 6:

Labels changed: added size-l.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Feb 1, 2013

Comment 7:

This issue was closed by revision b0a29f3.

Status changed to Fixed.

@dvyukov dvyukov added fixed labels Feb 1, 2013

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015

@rsc rsc removed the go1.1 label Apr 14, 2015

@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
4 participants
You can’t perform that action at this time.