summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-03-15 14:48:23 -0400
committerAustin Clements <austin@google.com>2017-03-15 22:16:10 +0000
commitf2e87158f06902daa44d34b4846611f8520e4491 (patch)
tree3d711895b4e05ce6347e408f9663c48fbf7ef759
parentc03e75e53915af9905bc261c66b5276de042ea1c (diff)
downloadgo-git-f2e87158f06902daa44d34b4846611f8520e4491.tar.gz
runtime: make GOTRACEBACK=crash crash promptly in cgo binaries
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>
-rw-r--r--src/runtime/proc.go4
-rw-r--r--src/runtime/signal_sighandler.go2
2 files changed, 5 insertions, 1 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index caeb51205b..45d98de151 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -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.
diff --git a/src/runtime/signal_sighandler.go b/src/runtime/signal_sighandler.go
index 5af12d7b2f..3b9ba296d9 100644
--- a/src/runtime/signal_sighandler.go
+++ b/src/runtime/signal_sighandler.go
@@ -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