Skip to content

Commit 7c22af8

Browse files
committed
runtime: fix deadlock in TestCrashDumpsAllThreads
TestCrashDumpsAllThreads carefully sets the number of Ps to one greater than the number of non-preemptible loops it starts so that the main goroutine can continue to run (necessary because of #10958). However, if GC starts, it can take over that one spare P and lock up the system while waiting for the non-preemptible loops, causing the test to eventually time out. This deadlock is easily reproducible if you run the runtime test with GOGC=1. Fix this by forcing GOGC=off when running this test. Change-Id: Ifb22da5ce33f9a61700a326ea92fcf4b049721d1 Reviewed-on: https://go-review.googlesource.com/19516 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
1 parent feb2a5d commit 7c22af8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/runtime/crash_unix_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"os/exec"
1515
"path/filepath"
1616
"runtime"
17+
"strings"
1718
"syscall"
1819
"testing"
1920
)
@@ -52,6 +53,18 @@ func TestCrashDumpsAllThreads(t *testing.T) {
5253
cmd = exec.Command(filepath.Join(dir, "a.exe"))
5354
cmd = testEnv(cmd)
5455
cmd.Env = append(cmd.Env, "GOTRACEBACK=crash")
56+
57+
// Set GOGC=off. Because of golang.org/issue/10958, the tight
58+
// loops in the test program are not preemptible. If GC kicks
59+
// in, it may lock up and prevent main from saying it's ready.
60+
newEnv := []string{}
61+
for _, s := range cmd.Env {
62+
if !strings.HasPrefix(s, "GOGC=") {
63+
newEnv = append(newEnv, s)
64+
}
65+
}
66+
cmd.Env = append(newEnv, "GOGC=off")
67+
5568
var outbuf bytes.Buffer
5669
cmd.Stdout = &outbuf
5770
cmd.Stderr = &outbuf

0 commit comments

Comments
 (0)