Skip to content

Commit 45967bb

Browse files
committed
runtime: soften up the GCTestIsReachable test a bit
This test can fail due to objects being incorrectly retained due to conservative scanning. Allow a bit of slop (1 accidentally retained object) to prevent flaky failures. Fixes #67204 "fixes" is a bit too strong a word. More like, hopefully reduces the false positive rate to something approaching 0. Change-Id: I09984f0cce50d8209aef19f3d89b0e295c86f8d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/590615 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7274921 commit 45967bb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/runtime/gc_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package runtime_test
66

77
import (
88
"fmt"
9+
"math/bits"
910
"math/rand"
1011
"os"
1112
"reflect"
@@ -278,8 +279,17 @@ func TestGCTestIsReachable(t *testing.T) {
278279
}
279280

280281
got := runtime.GCTestIsReachable(all...)
281-
if want != got {
282-
t.Fatalf("did not get expected reachable set; want %b, got %b", want, got)
282+
if got&want != want {
283+
// This is a serious bug - an object is live (due to the KeepAlive
284+
// call below), but isn't reported as such.
285+
t.Fatalf("live object not in reachable set; want %b, got %b", want, got)
286+
}
287+
if bits.OnesCount64(got&^want) > 1 {
288+
// Note: we can occasionally have a value that is retained even though
289+
// it isn't live, due to conservative scanning of stack frames.
290+
// See issue 67204. For now, we allow a "slop" of 1 unintentionally
291+
// retained object.
292+
t.Fatalf("dead object in reachable set; want %b, got %b", want, got)
283293
}
284294
runtime.KeepAlive(half)
285295
}

0 commit comments

Comments
 (0)