[Data Race]: potential new initroduced data race in Serving#3068
yanke-xu opened this issue · 5 comments
A new data race in serving#3068:
WARNING: DATA RACE
Read at 0x00c0000701f0 by goroutine 9:
runtime.chansend()
/usr/local/go/src/runtime/chan.go:158 +0x0
command-line-arguments.(*impl).Go()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:44 +0x84
command-line-arguments.TestServing3068.func1()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:65 +0x4b
Previous write at 0x00c0000701f0 by goroutine 7:
runtime.closechan()
/usr/local/go/src/runtime/chan.go:355 +0x0
command-line-arguments.(*impl).Wait.func1()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:49 +0x64
sync.(*Once).doSlow()
/usr/local/go/src/sync/once.go:68 +0x109
sync.(*Once).Do()
/usr/local/go/src/sync/once.go:59 +0x68
command-line-arguments.(*impl).Wait()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:48 +0x64
command-line-arguments.TestServing3068()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:72 +0x13b
testing.tRunner()
/usr/local/go/src/testing/testing.go:1203 +0x202
Goroutine 9 (running) created at:
command-line-arguments.TestServing3068()
/home/ubuntu2004/goProgram/src/GTrack/testdata/nonblocking/serving/3068/serving3068_test.go:63 +0x127
testing.tRunner()
/usr/local/go/src/testing/testing.go:1203 +0x202
Goroutine 7 (running) created at:
testing.(*T).Run()
/usr/local/go/src/testing/testing.go:1248 +0x5d7
testing.runTests.func1()
/usr/local/go/src/testing/testing.go:1521 +0xa6
testing.tRunner()
/usr/local/go/src/testing/testing.go:1203 +0x202
testing.runTests()
/usr/local/go/src/testing/testing.go:1519 +0x612
testing.(*M).Run()
/usr/local/go/src/testing/testing.go:1427 +0x3b3
main.main()
_testmain.go:43 +0x236
In addition, since the Goroutine 9 and Goroutine 7 are called in parallel, the two statements i.wg.Add(1)
and i.wg.Wait()
will be called in parallel, it can cause a data race.
As your backtrace discribes, goroutine 9 accesses runtime.chansend
and goroutine 7 accesses runtime.closechan
. This depends on how Go runtime reports the panic/race behavior caused by send on closed channel
. So I think it's the same bug, but different behavior on different versions of Go runtime.
OS:Ubuntu 20.04
Go Version:1.16.15
In fact,when I use go test -race
, both panic and data race are reported by the Go-runtime detector at the same time.
This is to be expected, GoBench was not tested on Go 1.16 in my impression. You can refer the release notes of Go 1.16:
Go 1.16 fixes a discrepancy between the race detector and the Go memory model. The race detector now more precisely follows the channel synchronization rules of the memory model. As a result, the detector may now report races it previously missed.
If I understand correctly, Go race detector has been enhanced in this release so it can report the race you mentioned. But I prefer that the original bug triggers the new bug.
Yes. Perhaps it would be better to update the backtrace or explain the experimental environment to reduce this divergence.
I truly appreciate it. I'll put a link to this issue in the documentation so that everyone can see what we've discussed.