Skip to content

Commit 29957c5

Browse files
committed
runtime: fix preemption deadlocks in TestDebugCall*
TestDebugCall* uses atomic spin loops and hence can deadlock if the garbage collector is enabled (because of #10958; ironically, implementing debugger call injection is closely related to fixing this exact issue, but we're not there yet). Fix this by disabling the garbage collector during these tests. Updates #25519 (might fix it, though I suspect not) Change-Id: If1e454b9cdea8e4b1cd82509b762c75b6acd8476 Reviewed-on: https://go-review.googlesource.com/114086 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 65c365b commit 29957c5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/runtime/debug_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ package runtime_test
1818
import (
1919
"fmt"
2020
"runtime"
21+
"runtime/debug"
2122
"sync/atomic"
2223
"syscall"
2324
"testing"
2425
)
2526

2627
func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
27-
// This can deadlock if there aren't enough threads.
28+
// This can deadlock if there aren't enough threads or if a GC
29+
// tries to interrupt an atomic loop (see issue #10958).
2830
ogomaxprocs := runtime.GOMAXPROCS(2)
31+
ogcpercent := debug.SetGCPercent(-1)
2932

3033
ready := make(chan *runtime.G)
3134
var stop uint32
@@ -39,6 +42,7 @@ func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
3942
t.Fatal(err)
4043
}
4144
runtime.GOMAXPROCS(ogomaxprocs)
45+
debug.SetGCPercent(ogcpercent)
4246
}
4347
}
4448

@@ -156,8 +160,10 @@ func debugCallUnsafePointWorker(gpp **runtime.G, ready, stop *uint32) {
156160
}
157161

158162
func TestDebugCallUnsafePoint(t *testing.T) {
159-
// This can deadlock if there aren't enough threads.
163+
// This can deadlock if there aren't enough threads or if a GC
164+
// tries to interrupt an atomic loop (see issue #10958).
160165
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))
166+
defer debug.SetGCPercent(debug.SetGCPercent(-1))
161167

162168
// Test that the runtime refuses call injection at unsafe points.
163169
var g *runtime.G

0 commit comments

Comments
 (0)