cache-example icon indicating copy to clipboard operation
cache-example copied to clipboard

FastCache datarace

Open KAIYOHUGO opened this issue 4 years ago • 0 comments

如題所述,fast/shard.go好像怪怪的,是不是要用Lock而不是RLock?還是我誤解了什麼?

WARNING: DATA RACE
Read at 0x00c00014ed88 by goroutine 112:
  container/list.(*List).MoveToBack()
      /usr/local/go/src/container/list/list.go:197 +0x4b8
  test/fast.(*cacheShard).get()
      /home/runner/test/fast/shard.go:63 +0x12b
  test/fast.(*fastCache).Get()
      /home/runner/test/fast/cache.go:32 +0xd8
  test.BenchmarkT.func2()
      /home/runner/test/main_test.go:17 +0x90

Previous write at 0x00c00014ed88 by goroutine 58:
  container/list.(*List).move()
      /usr/local/go/src/container/list/list.go:131 +0x3e6
  container/list.(*List).MoveToBack()
      /usr/local/go/src/container/list/list.go:201 +0x20d
  test/fast.(*cacheShard).get()
      /home/runner/test/fast/shard.go:63 +0x12b
  test/fast.(*fastCache).Get()
      /home/runner/test/fast/cache.go:32 +0xd8
  test.BenchmarkT.func2()
      /home/runner/test/main_test.go:17 +0x90

Goroutine 112 (running) created at:
  test.BenchmarkT()
      /home/runner/test/main_test.go:16 +0xc3
  testing.(*B).runN()
      /usr/local/go/src/testing/benchmark.go:191 +0x1b4
  testing.(*B).launch()
      /usr/local/go/src/testing/benchmark.go:321 +0x15c

Goroutine 58 (finished) created at:
  test.BenchmarkT()
      /home/runner/test/main_test.go:16 +0xc3
  testing.(*B).runN()
      /usr/local/go/src/testing/benchmark.go:191 +0x1b4
  testing.(*B).launch()
      /usr/local/go/src/testing/benchmark.go:321 +0x15c
==================
==================
WARNING: DATA RACE
Read at 0x00c000148248 by goroutine 67:
  container/list.(*List).MoveToBack()
      /usr/local/go/src/container/list/list.go:197 +0x4b8
  test/fast.(*cacheShard).get()
      /home/runner/test/fast/shard.go:63 +0x12b
  test/fast.(*fastCache).Get()
      /home/runner/test/fast/cache.go:32 +0xd8
  test.BenchmarkT.func2()
      /home/runner/test/main_test.go:17 +0x90

Previous write at 0x00c000148248 by goroutine 51:
  [failed to restore the stack]

Goroutine 67 (running) created at:
  test.BenchmarkT()
      /home/runner/test/main_test.go:16 +0xc3
  testing.(*B).runN()
      /usr/local/go/src/testing/benchmark.go:191 +0x1b4
  testing.(*B).launch()
      /usr/local/go/src/testing/benchmark.go:321 +0x15c

Goroutine 51 (finished) created at:
  test.BenchmarkT()
      /home/runner/test/main_test.go:16 +0xc3
  testing.(*B).runN()
      /usr/local/go/src/testing/benchmark.go:191 +0x1b4
  testing.(*B).launch()
      /usr/local/go/src/testing/benchmark.go:321 +0x15c
........略

KAIYOHUGO avatar Jul 10 '21 10:07 KAIYOHUGO