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

Fixes race in getKeyMetadata accessor, when called from KeyMetadata #233

Merged
merged 1 commit into from
Jul 6, 2020
Merged

Fixes race in getKeyMetadata accessor, when called from KeyMetadata #233

merged 1 commit into from
Jul 6, 2020

Conversation

cognusion
Copy link
Contributor

@cognusion cognusion commented Jul 6, 2020

All(?) cases where cacheShard.getKeyMetadata() was called were wrapped in a lock, except when KeyMetadata was used, resulting in a race between when a key was deleted via cacheShard.removeOldestEntry and read via cacheShard.getKeyMetadata().

WARNING: DATA RACE
Write at 0x00c01697d9b0 by goroutine 133:
  runtime.mapdelete_fast64()
      /home/m/Documents/workspace/go/src/runtime/map_fast64.go:272 +0x0
  github.com/allegro/bigcache/v2.(*cacheShard).removeOldestEntry()
      /home/m/gocode/src/github.com/cognusion/bigcache/shard.go:304 +0x360
  github.com/allegro/bigcache/v2.(*cacheShard).removeOldestEntry-fm()
      /home/m/gocode/src/github.com/cognusion/bigcache/shard.go:293 +0x49
  github.com/allegro/bigcache/v2.(*cacheShard).onEvict()
      /home/m/gocode/src/github.com/cognusion/bigcache/shard.go:249 +0x1cf
  github.com/allegro/bigcache/v2.(*cacheShard).cleanUp()
      /home/m/gocode/src/github.com/cognusion/bigcache/shard.go:260 +0xd8
  github.com/allegro/bigcache/v2.(*BigCache).cleanUp()
      /home/m/gocode/src/github.com/cognusion/bigcache/bigcache.go:215 +0x8b
  github.com/allegro/bigcache/v2.newBigCache.func1()
      /home/m/gocode/src/github.com/cognusion/bigcache/bigcache.go:92 +0xb4

Previous read at 0x00c01697d9b0 by goroutine 28:
  runtime.mapaccess1_fast64()
      /home/m/Documents/workspace/go/src/runtime/map_fast64.go:12 +0x0
  github.com/allegro/bigcache/v2.(*cacheShard).getKeyMetadata()
      /home/m/gocode/src/github.com/cognusion/bigcache/shard.go:348 +0x130
  github.com/allegro/bigcache/v2.(*BigCache).KeyMetadata()
      /home/m/gocode/src/github.com/cognusion/bigcache/bigcache.go:196 +0x14f
  github.com/allegro/bigcache/v2.TestWriteAndReadParallelSameKeyWithStats()
      /home/m/gocode/src/github.com/cognusion/bigcache/bigcache_test.go:699 +0x5f9
  testing.tRunner()
      /home/m/Documents/workspace/go/src/testing/testing.go:991 +0x1eb

Copy link
Collaborator

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@cristaloleg cristaloleg merged commit 21e5ca5 into allegro:master Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants