Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: b.Cleanup(nil) panics #38346

Closed
cuonglm opened this issue Apr 10, 2020 · 2 comments
Closed

testing: b.Cleanup(nil) panics #38346

cuonglm opened this issue Apr 10, 2020 · 2 comments

Comments

@cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Apr 10, 2020

What version of Go are you using (go version)?

$ go version
go version devel +7c0ee1127b Thu Apr 9 16:15:34 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

func BenchmarkNewEmptyMap(b *testing.B) {
        b.ReportAllocs()
        b.Cleanup(func() { b.Log("Start logginng") })
        for i := 0; i < b.N; i++ {
                _ = make(map[int]int)
                if i == 1000 {
                        b.Cleanup(nil)
                }
        }
}

What did you expect to see?

Run benchmark ok.

What did you see instead?

go test -run=NONE -bench='BenchmarkNewEmptyMap$' -count=10
goos: darwin
goarch: amd64
pkg: runtime
BenchmarkNewEmptyMap-12    	       0	              NaN ns/op	       0 B/op	       0 allocs/op
--- BENCH: BenchmarkNewEmptyMap-12
    map_benchmark_test.go:312: Start logginng
    map_benchmark_test.go:312: Start logginng
    map_benchmark_test.go:312: Start logginng
BenchmarkNewEmptyMap-12    	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10e6f3a]

goroutine 7 [running]:
panic(0x123cd40, 0x146fcc0)
	/Users/cuonglm/sources/go/src/runtime/panic.go:1064 +0x43a fp=0xc000059e58 sp=0xc000059da0 pc=0x103521a
runtime.panicmem(...)
	/Users/cuonglm/sources/go/src/runtime/panic.go:212
runtime.sigpanic()
	/Users/cuonglm/sources/go/src/runtime/signal_unix.go:719 +0x3ca fp=0xc000059e88 sp=0xc000059e58 pc=0x104af4a
testing.(*common).Cleanup.func1()
	/Users/cuonglm/sources/go/src/testing/testing.go:796 +0x4a fp=0xc000059eb0 sp=0xc000059e88 pc=0x10e6f3a
testing.(*common).runCleanup(0xc00000c1e0, 0x0, 0x0, 0x0)
	/Users/cuonglm/sources/go/src/testing/testing.go:850 +0xa7 fp=0xc000059ee8 sp=0xc000059eb0 pc=0x10e2ba7
testing.(*B).runN(0xc00000c1e0, 0x2710)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:199 +0x139 fp=0xc000059f58 sp=0xc000059ee8 pc=0x10da3d9
testing.(*B).launch(0xc00000c1e0)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:321 +0xea fp=0xc000059fd8 sp=0xc000059f58 pc=0x10daa1a
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000059fe0 sp=0xc000059fd8 pc=0x1070d21
created by testing.(*B).doBench
	/Users/cuonglm/sources/go/src/testing/benchmark.go:276 +0x55

goroutine 1 [chan receive]:
runtime.gopark(0x129c318, 0xc00008e1d8, 0x80012170e, 0x2)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc0001237c8 sp=0xc0001237a8 pc=0x1038010
runtime.chanrecv(0xc00008e180, 0x0, 0xc000000101, 0x10da4dd)
	/Users/cuonglm/sources/go/src/runtime/chan.go:567 +0x33d fp=0xc000123858 sp=0xc0001237c8 pc=0x1007a1d
runtime.chanrecv1(0xc00008e180, 0x0)
	/Users/cuonglm/sources/go/src/runtime/chan.go:434 +0x2b fp=0xc000123888 sp=0xc000123858 pc=0x100768b
testing.(*B).run1(0xc00000c3c0, 0xc00000c3c0)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:233 +0x9e fp=0xc000123950 sp=0xc000123888 pc=0x10da4fe
testing.(*benchContext).processBench(0xc0000b4180, 0xc00000c3c0)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:566 +0x1ee fp=0xc000123a78 sp=0xc000123950 pc=0x10dc13e
testing.(*B).run(0xc00000c1e0)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:268 +0x63 fp=0xc000123ad0 sp=0xc000123a78 pc=0x10da833
testing.(*B).Run(0xc00010c000, 0x128d08a, 0x14, 0x129d138, 0x10da000)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:652 +0x3fd fp=0xc000123bb8 sp=0xc000123ad0 pc=0x10dcd5d
testing.runBenchmarks.func1(0xc00010c000)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:533 +0x78 fp=0xc000123c08 sp=0xc000123bb8 pc=0x10e6868
testing.(*B).runN(0xc00010c000, 0x1)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:191 +0xe8 fp=0xc000123c78 sp=0xc000123c08 pc=0x10da388
testing.runBenchmarks(0x12875cc, 0x7, 0xc0000b4160, 0x1477c80, 0xf2, 0xf2, 0x147c900)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:539 +0x390 fp=0xc000123d70 sp=0xc000123c78 pc=0x10dbc40
testing.(*M).Run(0xc0000e0000, 0x0)
	/Users/cuonglm/sources/go/src/testing/testing.go:1256 +0x511 fp=0xc000123e80 sp=0xc000123d70 pc=0x10e3ea1
runtime_test.TestMain(0xc0000e0000)
	/Users/cuonglm/sources/go/src/runtime/crash_test.go:28 +0x2f fp=0xc000123ed0 sp=0xc000123e80 pc=0x117b39f
main.main()
	_testmain.go:1195 +0x15f fp=0xc000123f88 sp=0xc000123ed0 pc=0x12021bf
runtime.main()
	/Users/cuonglm/sources/go/src/runtime/proc.go:204 +0x212 fp=0xc000123fe0 sp=0xc000123f88 pc=0x1037c32
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000123fe8 sp=0xc000123fe0 pc=0x1070d21

goroutine 2 [force gc (idle)]:
runtime.gopark(0x129c660, 0x147c0f0, 0x1411, 0x1)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000048fb0 sp=0xc000048f90 pc=0x1038010
runtime.goparkunlock(...)
	/Users/cuonglm/sources/go/src/runtime/proc.go:312
runtime.forcegchelper()
	/Users/cuonglm/sources/go/src/runtime/proc.go:255 +0xbc fp=0xc000048fe0 sp=0xc000048fb0 pc=0x1037ebc
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000048fe8 sp=0xc000048fe0 pc=0x1070d21
created by runtime.init.6
	/Users/cuonglm/sources/go/src/runtime/proc.go:243 +0x35

goroutine 3 [GC sweep wait]:
runtime.gopark(0x129c660, 0x147c500, 0x140c, 0x1)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc0000497a8 sp=0xc000049788 pc=0x1038010
runtime.goparkunlock(...)
	/Users/cuonglm/sources/go/src/runtime/proc.go:312
runtime.bgsweep(0xc000070000)
	/Users/cuonglm/sources/go/src/runtime/mgcsweep.go:90 +0x135 fp=0xc0000497d8 sp=0xc0000497a8 pc=0x1025085
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0000497e0 sp=0xc0000497d8 pc=0x1070d21
created by runtime.gcenable
	/Users/cuonglm/sources/go/src/runtime/mgc.go:217 +0x5c

goroutine 4 [sleep]:
runtime.gopark(0x129c660, 0x147c4c0, 0x1313, 0x2)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000049f20 sp=0xc000049f00 pc=0x1038010
runtime.goparkunlock(...)
	/Users/cuonglm/sources/go/src/runtime/proc.go:312
runtime.scavengeSleep(0x17c21f, 0x3f53b)
	/Users/cuonglm/sources/go/src/runtime/mgcscavenge.go:214 +0xc0 fp=0xc000049f78 sp=0xc000049f20 pc=0x10235a0
runtime.bgscavenge(0xc000070000)
	/Users/cuonglm/sources/go/src/runtime/mgcscavenge.go:316 +0x193 fp=0xc000049fd8 sp=0xc000049f78 pc=0x1023763
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000049fe0 sp=0xc000049fd8 pc=0x1070d21
created by runtime.gcenable
	/Users/cuonglm/sources/go/src/runtime/mgc.go:218 +0x7e

goroutine 18 [finalizer wait]:
runtime.gopark(0x129c660, 0x14a69a0, 0x81410, 0x1)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000048758 sp=0xc000048738 pc=0x1038010
runtime.goparkunlock(...)
	/Users/cuonglm/sources/go/src/runtime/proc.go:312
runtime.runfinq()
	/Users/cuonglm/sources/go/src/runtime/mfinal.go:175 +0xa4 fp=0xc0000487e0 sp=0xc000048758 pc=0x101ac04
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0000487e8 sp=0xc0000487e0 pc=0x1070d21
created by runtime.createfing
	/Users/cuonglm/sources/go/src/runtime/mfinal.go:156 +0x61

goroutine 29 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180000, 0xc000081418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000044760 sp=0xc000044740 pc=0x1038010
runtime.gcBgMarkWorker(0xc000026000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc0000447d8 sp=0xc000044760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0000447e0 sp=0xc0000447d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 34 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc00001c0d0, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000188760 sp=0xc000188740 pc=0x1038010
runtime.gcBgMarkWorker(0xc000028800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc0001887d8 sp=0xc000188760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0001887e0 sp=0xc0001887d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 30 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180010, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000044f60 sp=0xc000044f40 pc=0x1038010
runtime.gcBgMarkWorker(0xc00002b000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc000044fd8 sp=0xc000044f60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000044fe0 sp=0xc000044fd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 31 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc0000a64d0, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000045760 sp=0xc000045740 pc=0x1038010
runtime.gcBgMarkWorker(0xc00002d800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc0000457d8 sp=0xc000045760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0000457e0 sp=0xc0000457d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 32 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc00001c0e0, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000045f60 sp=0xc000045f40 pc=0x1038010
runtime.gcBgMarkWorker(0xc000030000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc000045fd8 sp=0xc000045f60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000045fe0 sp=0xc000045fd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 35 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc00001c0f0, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000188f60 sp=0xc000188f40 pc=0x1038010
runtime.gcBgMarkWorker(0xc000032800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc000188fd8 sp=0xc000188f60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000188fe0 sp=0xc000188fd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 33 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180020, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000046760 sp=0xc000046740 pc=0x1038010
runtime.gcBgMarkWorker(0xc000035000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc0000467d8 sp=0xc000046760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0000467e0 sp=0xc0000467d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 36 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc00001c100, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000189760 sp=0xc000189740 pc=0x1038010
runtime.gcBgMarkWorker(0xc000037800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc0001897d8 sp=0xc000189760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc0001897e0 sp=0xc0001897d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 50 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180030, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000046f60 sp=0xc000046f40 pc=0x1038010
runtime.gcBgMarkWorker(0xc00003a000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc000046fd8 sp=0xc000046f60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000046fe0 sp=0xc000046fd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 5 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180040, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc00004a760 sp=0xc00004a740 pc=0x1038010
runtime.gcBgMarkWorker(0xc00003c800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc00004a7d8 sp=0xc00004a760 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00004a7e0 sp=0xc00004a7d8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 37 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc0000a64e0, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc000189f60 sp=0xc000189f40 pc=0x1038010
runtime.gcBgMarkWorker(0xc00003f000)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc000189fd8 sp=0xc000189f60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc000189fe0 sp=0xc000189fd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 6 [GC worker (idle)]:
runtime.gopark(0x129c438, 0xc000180050, 0x1418, 0x0)
	/Users/cuonglm/sources/go/src/runtime/proc.go:306 +0xe0 fp=0xc00004af60 sp=0xc00004af40 pc=0x1038010
runtime.gcBgMarkWorker(0xc000041800)
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1891 +0xff fp=0xc00004afd8 sp=0xc00004af60 pc=0x101e64f
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00004afe0 sp=0xc00004afd8 pc=0x1070d21
created by runtime.gcBgMarkStartWorkers
	/Users/cuonglm/sources/go/src/runtime/mgc.go:1839 +0x77

goroutine 66 [runnable]:
testing.(*B).run1.func1(0xc00000c3c0)
	/Users/cuonglm/sources/go/src/testing/benchmark.go:224 fp=0xc00018afd8 sp=0xc00018afd0 pc=0x10e6560
runtime.goexit()
	/Users/cuonglm/sources/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00018afe0 sp=0xc00018afd8 pc=0x1070d21
created by testing.(*B).run1
	/Users/cuonglm/sources/go/src/testing/benchmark.go:224 +0x7d
exit status 2
FAIL	runtime	0.073s
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 10, 2020

Change https://golang.org/cl/227800 mentions this issue: testing: check f is not nil before calling in Cleanup

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 10, 2020

I'm not really seeing why this is a problem. fmt.Fprintln(nil, "") also crashes. Some standard library functions will panic if you pass nil. That seems OK.

@cuonglm cuonglm closed this Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.