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

fix: missing read lock in MapWithTTL #1445

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

VinozzZ
Copy link
Contributor

@VinozzZ VinozzZ commented Nov 21, 2024

Which problem is this PR solving?

fatal error: concurrent map read and map write

goroutine 193 [running]:
github.com/honeycombio/refinery/generics.(*MapWithTTL[...]).SortedValues(0xdd8a60)
	github.com/honeycombio/refinery/generics/mapttl.go:118 +0xcc
github.com/honeycombio/refinery/internal/peer.(*RedisPubsubPeers).Ready.func1()
	github.com/honeycombio/refinery/internal/peer/pubsub_redis.go:212 +0x454
created by github.com/honeycombio/refinery/internal/peer.(*RedisPubsubPeers).Ready in goroutine 1
	github.com/honeycombio/refinery/internal/peer/pubsub_redis.go:180 +0x84

Short description of the changes

  • add RLock for SortedValues

@VinozzZ VinozzZ added this to the v2.9 milestone Nov 21, 2024
@VinozzZ VinozzZ self-assigned this Nov 21, 2024
@VinozzZ VinozzZ requested a review from a team as a code owner November 21, 2024 17:50
Copy link
Contributor

@kentquirk kentquirk left a comment

Choose a reason for hiding this comment

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

I forgot that indexing Items needed a lock.

This solution uses two lock cycles (one to get the sorted keys, and a second one you add here).

I think that's preferable to a single lock because the sort takes place without holding the lock. So yeah, let's go with this.

@VinozzZ VinozzZ merged commit 7f14374 into main Nov 21, 2024
7 checks passed
@VinozzZ VinozzZ deleted the yingrong/fix_concurrent_map_access branch November 21, 2024 18:45
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