Skip to content

fix panic on concurrent map read#1

Merged
fschoell merged 1 commit into
mainfrom
fix/concurrent_read_access
Jul 14, 2026
Merged

fix panic on concurrent map read#1
fschoell merged 1 commit into
mainfrom
fix/concurrent_read_access

Conversation

@fschoell

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a concurrency bug in UpdateCache where concurrent access to the shared entries map across distinct keys could trigger a concurrent map read and map write panic. It does so by introducing an RWMutex to protect map reads/writes while preserving per-key serialization for the update path.

Changes:

  • Replaced the cache-wide *sync.Mutex with a cache-wide sync.RWMutex and used RLock/RUnlock for reads in Get.
  • Updated Get to safely read the map under a read lock and write under a write lock, preventing concurrent map access panics.
  • Added a parallel test that exercises concurrent Get calls across many distinct keys to reproduce/guard against the panic (especially under -race).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cache.go Adds an RWMutex and uses it to protect concurrent reads/writes of the entries map in Get (and write-locking in Prune).
cache_test.go Adds a parallel distinct-keys test to validate the cache no longer panics under concurrent access patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fschoell
fschoell merged commit 58bbe3c into main Jul 14, 2026
2 checks passed
@fschoell
fschoell deleted the fix/concurrent_read_access branch July 14, 2026 17:52
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