]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make GOTRACEBACK=crash crash promptly in cgo binaries
authorAustin Clements <austin@google.com>
Wed, 15 Mar 2017 18:48:23 +0000 (14:48 -0400)
committerAustin Clements <austin@google.com>
Wed, 15 Mar 2017 22:16:10 +0000 (22:16 +0000)
GOTRACEBACK=crash works by bouncing a SIGQUIT around the process
sched.mcount times. However, sched.mcount includes the extra Ms
allocated by oneNewExtraM for cgo callbacks. Hence, if there are any
extra Ms that don't have real OS threads, we'll try to send SIGQUIT
more times than there are threads to catch it. Since nothing will
catch these extra signals, we'll fall back to blocking for five
seconds before aborting the process.

Avoid this five second delay by subtracting out the number of extra Ms
when sending SIGQUITs.

Of course, in a cgo binary, it's still possible for the SIGQUIT to go
to a cgo thread and cause some other failure mode. This does not fix
that.

Change-Id: I4fbf3c52dd721812796c4c1dcb2ab4cb7026d965
Reviewed-on: https://go-review.googlesource.com/38182
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/proc.go
src/runtime/signal_sighandler.go

index caeb51205b0ce53500fea256a6931df3bd864b08..45d98de151762e7bb7a788c49274e608b948ae40 100644 (file)
@@ -1399,6 +1399,7 @@ func needm(x byte) {
        // running at all (that is, there's no garbage collection
        // running right now).
        mp.needextram = mp.schedlink == 0
+       extraMCount--
        unlockextra(mp.schedlink.ptr())
 
        // Save and block signals before installing g.
@@ -1484,6 +1485,7 @@ func oneNewExtraM() {
        // Add m to the extra list.
        mnext := lockextra(true)
        mp.schedlink.set(mnext)
+       extraMCount++
        unlockextra(mp)
 }
 
@@ -1525,6 +1527,7 @@ func dropm() {
        unminit()
 
        mnext := lockextra(true)
+       extraMCount++
        mp.schedlink.set(mnext)
 
        setg(nil)
@@ -1541,6 +1544,7 @@ func getm() uintptr {
 }
 
 var extram uintptr
+var extraMCount uint32 // Protected by lockextra
 var extraMWaiters uint32
 
 // lockextra locks the extra list and returns the list head.
index 5af12d7b2fedb8c42aa4c2349f26e07ce6c95cb6..3b9ba296d94309c8a86621b1caef1abadcce0d29 100644 (file)
@@ -111,7 +111,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
 
        if docrash {
                crashing++
-               if crashing < sched.mcount {
+               if crashing < sched.mcount-int32(extraMCount) {
                        // There are other m's that need to dump their stacks.
                        // Relay SIGQUIT to the next m by sending it to the current process.
                        // All m's that have already received SIGQUIT have signal masks blocking