-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: race-detector crash when using cgo and threads #17190
Comments
How can we recreate the problem? CC @dvyukov |
Currently I don't know how to strip my complex networking code to minimal working example. runtime: invalid pc-encoded table f=runtime.needm pc=0x499898 targetpc=0x49989f tab=[0/0]0x0
value=56 until pc=0x499898
runtime: invalid pc-encoded table f=runtime.needm pc=0x499898 targetpc=0x49989f tab=[0/0]0x0
value=1342 until pc=0x49975e
value=1343 until pc=0x499778
value=1354 until pc=0x49978b
value=1363 until pc=0x49979e
value=1364 until pc=0x4997bc
value=1372 until pc=0x4997ca
value=1373 until pc=0x4997cf
value=1380 until pc=0x4997e0
value=1381 until pc=0x4997ee
value=1342 until pc=0x4997f3
value=1382 until pc=0x499810
value=1342 until pc=0x499815
value=1383 until pc=0x499832
value=1384 until pc=0x49983c
value=1387 until pc=0x499841
value=1388 until pc=0x499846
value=1389 until pc=0x499850
value=1346 until pc=0x499880
value=1347 until pc=0x49988c
value=1354 until pc=0x499891
value=1346 until pc=0x499898
==================
WARNING: DATA RACE
Read at 0x00c42001e158 by goroutine 28:
main.(*Ctl).reportAll()
/home/go/src/mophon/ctl.go:100 +0xf4
main.(*Ctl).worker.func1()
/home/go/src/mophon/ctl.go:154 +0x8e7
Previous write at 0x00c42001e158 by goroutine 2:
main.onRegState()
/home/go/src/mophon/pjsip.go:140 +0x554
main._cgoexpwrap_a6764208b0c4_onRegState()
??:0 +0x40
Goroutine 28 (running) created at:
main.(*Ctl).worker()
/home/go/src/mophon/ctl.go:187 +0xa2a
main.(*Program).Start.func1.2()
/home/go/src/mophon/main.go:205 +0x170
Goroutine 2 (running) created at:
runtime.needm()
?@ACDFILMNPSTUZ["\ [some binary garbage from memory skipped] According to it, I have race-condition between Go code working in goroutine (ctl.go) and Go code called as callback from one of threads in C-library (pjsip.go), but race-detector can't get some info to show stacktraces. External library is not stripped. |
Finally I got working example: main.go: package main
/*
#cgo CFLAGS: -Wall -O2 -Wno-unused-function
#cgo linux LDFLAGS: -lpthread
typedef struct cb {
void (*on_test)();
} cb;
extern void start_test(cb *c);
extern void onTest();
static void test_cb(cb *c) {
c->on_test = &onTest;
}
*/
import "C"
type T struct {
t int
}
var t = &T{}
//export onTest
func onTest() {
t.t++
}
func main() {
var c C.cb
C.test_cb(&c)
C.start_test(&c)
go func() {
for {
t.t++
}
}()
for {}
} lib.go: package main
/*
#cgo CFLAGS: -Wall -O2 -Wno-unused-function
#include <pthread.h>
typedef struct cb {
void (*on_test)();
} cb;
void *call_test(void *p) {
cb *c = (cb*)p;
c->on_test();
return NULL;
}
void start_test(cb *c) {
pthread_t thr;
pthread_create(&thr, NULL, call_test, c);
}
*/
import "C" |
@sisoftrg thanks for the reproducer. There are 2 bugs. First is that race detector incorrectly subtracts 1 (or maybe somebody forgot to add 1) to a PC, so it asks to symbolize off by one PC:
Second is that gentraceback crashes on this (I guess user can trigger this crash by calling one of public runtime functions as well):
|
This is broken on so many levels... |
CL https://golang.org/cl/29713 mentions this issue. |
CL https://golang.org/cl/29714 mentions this issue. |
CL https://golang.org/cl/29712 mentions this issue. |
PC passed to racegostart is expected to be a return PC of the go statement. Race runtime will subtract 1 from the PC before symbolization. Passing start PC of a function is wrong. Add sys.PCQuantum to the function start PC. Update #17190 Change-Id: Ia504c49e79af84ed4ea360c2aea472b370ea8bf5 Reviewed-on: https://go-review.googlesource.com/29712 Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Don't write line info for types, we don't have it. Otherwise types look like: type _Ctype_struct_cb struct { //line :1 on_test *[0]byte //line :1 } Which is not useful. Moreover we never override source info, so subsequent source code uses the same source info. Moreover, empty file name makes compile emit no source debug info at all. Update #17190 Change-Id: I7ae6fa4964520d7665743d340419b787df0b51e8 Reviewed-on: https://go-review.googlesource.com/29713 Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
What version of Go are you using (
go version
)?go1.7.1 linux/amd64
What operating system and processor architecture are you using (
go env
)?I'm use external library (pjsip, which using pthreads) with help of cgo. Without enabled race-detector all works well, but I want to debug some race-conditions in Go code.
When I turn on race-detector, app crashes after external library creates some threads.
Crash log:
The text was updated successfully, but these errors were encountered: