Skip to content

Commit ab4085c

Browse files
committed
runtime/pprof: call runtime.GC twice in memory profile test
This change fixes #46500 by working around #45315 which may cause freed objects to get missed in the heap profile published for the test. By calling runtime.GC one more time this change ensures that all freed objects are accounted for. Fixes #46500. Change-Id: Iedcd0b37dbaffa688b0ff8631a8b79f7a1169634 Reviewed-on: https://go-review.googlesource.com/c/go/+/333549 Trust: Michael Knyszek <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 296ddf2 commit ab4085c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/runtime/pprof/mprof_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ func TestMemoryProfiler(t *testing.T) {
8686

8787
runtime.GC() // materialize stats
8888

89+
// TODO(mknyszek): Fix #45315 and remove this extra call.
90+
//
91+
// Unfortunately, it's possible for the sweep termination condition
92+
// to flap, so with just one runtime.GC call, a freed object could be
93+
// missed, leading this test to fail. A second call reduces the chance
94+
// of this happening to zero, because sweeping actually has to finish
95+
// to move on to the next GC, during which nothing will happen.
96+
//
97+
// See #46500 for more details.
98+
runtime.GC()
99+
89100
memoryProfilerRun++
90101

91102
tests := []struct {

0 commit comments

Comments
 (0)