Skip to content

Instantly share code, notes, and snippets.

@pracucci
Created December 23, 2020 13:27
Show Gist options
  • Save pracucci/09cc52e0cd35c8b96cc8cac79bda78fd to your computer and use it in GitHub Desktop.
Save pracucci/09cc52e0cd35c8b96cc8cac79bda78fd to your computer and use it in GitHub Desktop.
=== RUN TestWaitGroup_Race
==================
WARNING: DATA RACE
Write at 0x00c000128208 by goroutine 7:
internal/race.Write()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/internal/race/race.go:41 +0x114
sync.(*WaitGroup).Wait()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/sync/waitgroup.go:128 +0x115
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:19 +0xa6
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
Previous read at 0x00c000128208 by goroutine 8:
internal/race.Read()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/internal/race/race.go:37 +0x1e8
sync.(*WaitGroup).Add()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/sync/waitgroup.go:71 +0x1fb
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race.func1()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:13 +0x4a
Goroutine 7 (running) created at:
testing.(*T).Run()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1105 +0x700
testing.runTests.func1()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1349 +0xa6
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
testing.runTests()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1347 +0x527
testing.(*M).Run()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1264 +0x43f
main.main()
_testmain.go:44 +0x223
Goroutine 8 (running) created at:
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:11 +0x8f
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
==================
==================
WARNING: DATA RACE
Read at 0x00c000128208 by goroutine 8:
internal/race.Read()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/internal/race/race.go:37 +0x1e8
sync.(*WaitGroup).Add()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/sync/waitgroup.go:71 +0x1fb
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race.func1()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:13 +0x4a
Previous write at 0x00c000128208 by goroutine 7:
internal/race.Write()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/internal/race/race.go:41 +0x114
sync.(*WaitGroup).Wait()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/sync/waitgroup.go:128 +0x115
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:19 +0xa6
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
Goroutine 8 (running) created at:
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race()
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:11 +0x8f
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
Goroutine 7 (running) created at:
testing.(*T).Run()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1105 +0x700
testing.runTests.func1()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1349 +0xa6
testing.tRunner()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1eb
testing.runTests()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1347 +0x527
testing.(*M).Run()
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1264 +0x43f
main.main()
_testmain.go:44 +0x223
==================
testing.go:969: race detected during execution of test
--- FAIL: TestWaitGroup_Race (0.00s)
panic: sync: WaitGroup is reused before previous Wait has returned [recovered]
panic: sync: WaitGroup is reused before previous Wait has returned
goroutine 19 [running]:
testing.tRunner.func1.1(0x11dab40, 0x12422e0)
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1003 +0x452
testing.tRunner.func1(0xc000168120)
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1006 +0x600
panic(0x11dab40, 0x12422e0)
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/runtime/panic.go:975 +0x3e3
sync.(*WaitGroup).Wait(0xc000128200)
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/sync/waitgroup.go:132 +0x18d
github.com/cortexproject/cortex/pkg/util/concurrency.TestWaitGroup_Race(0xc000168120)
/Users/marco/workspace/src/github.com/cortexproject/cortex/pkg/util/concurrency/waitgroup_test.go:19 +0xa7
testing.tRunner(0xc000168120, 0x121bb00)
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1054 +0x1ec
created by testing.(*T).Run
/usr/local/Cellar/go@1.14/1.14.9/libexec/src/testing/testing.go:1105 +0x701
Process finished with exit code 1
func TestWaitGroup_Race(t *testing.T) {
wg := sync.WaitGroup{}
go func() {
for i := 0; i < 10000; i++ {
wg.Add(1)
wg.Done()
}
}()
for i := 0; i < 10000; i++ {
wg.Wait()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment