Skip to content

Commit 871d63f

Browse files
committed
runtime: call runtime.GC in several tests that disable GC
These tests disable GC because of the potential for a deadlock, but don't consider that a GC could be in progress due to other tests. The likelihood of this case was increased when the minimum heap size was lowered during the Go 1.18 cycle. The issue was then mitigated by CL 368137 but in theory is always a problem. This change is intended specifically for #45867, but I just walked over a whole bunch of other tests that don't take this precaution where it seems like it could be relevant (some tests it's not, like the UserForcedGC test, or testprogs where no other code has run before it). Fixes #45867. Change-Id: I6a1b4ae73e05cab5a0b2d2cce14126bd13be0ba5 Reviewed-on: https://go-review.googlesource.com/c/go/+/369747 Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: David Chase <[email protected]> Trust: Michael Knyszek <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 8ea0ffb commit 871d63f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/runtime/proc_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ func TestGoroutineParallelism(t *testing.T) {
119119
// since the goroutines can't be stopped/preempted.
120120
// Disable GC for this test (see issue #10958).
121121
defer debug.SetGCPercent(debug.SetGCPercent(-1))
122+
// Now that GCs are disabled, block until any outstanding GCs
123+
// are also done.
124+
runtime.GC()
122125
for try := 0; try < N; try++ {
123126
done := make(chan bool)
124127
x := uint32(0)
@@ -163,6 +166,9 @@ func testGoroutineParallelism2(t *testing.T, load, netpoll bool) {
163166
// since the goroutines can't be stopped/preempted.
164167
// Disable GC for this test (see issue #10958).
165168
defer debug.SetGCPercent(debug.SetGCPercent(-1))
169+
// Now that GCs are disabled, block until any outstanding GCs
170+
// are also done.
171+
runtime.GC()
166172
for try := 0; try < N; try++ {
167173
if load {
168174
// Create P goroutines and wait until they all run.
@@ -623,6 +629,9 @@ func TestSchedLocalQueueEmpty(t *testing.T) {
623629
// If runtime triggers a forced GC during this test then it will deadlock,
624630
// since the goroutines can't be stopped/preempted during spin wait.
625631
defer debug.SetGCPercent(debug.SetGCPercent(-1))
632+
// Now that GCs are disabled, block until any outstanding GCs
633+
// are also done.
634+
runtime.GC()
626635

627636
iters := int(1e5)
628637
if testing.Short() {

src/runtime/testdata/testprog/badtraceback.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func init() {
1717
func BadTraceback() {
1818
// Disable GC to prevent traceback at unexpected time.
1919
debug.SetGCPercent(-1)
20+
// Out of an abundance of caution, also make sure that there are
21+
// no GCs actively in progress.
22+
runtime.GC()
2023

2124
// Run badLR1 on its own stack to minimize the stack size and
2225
// exercise the stack bounds logic in the hex dump.

src/runtime/testdata/testprog/preempt.go

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func AsyncPreempt() {
2020
runtime.GOMAXPROCS(1)
2121
// Disable GC so we have complete control of what we're testing.
2222
debug.SetGCPercent(-1)
23+
// Out of an abundance of caution, also make sure that there are
24+
// no GCs actively in progress.
25+
runtime.GC()
2326

2427
// Start a goroutine with no sync safe-points.
2528
var ready, ready2 uint32

0 commit comments

Comments
 (0)