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: concurrent omap reads #1608

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix: concurrent omap reads #1608

wants to merge 1 commit into from

Conversation

pd93
Copy link
Member

@pd93 pd93 commented Apr 21, 2024

Fixes #1605

Adds a mutex to omap.OrderedMap so that it is safe for use in goroutines.

@@ -61,16 +64,31 @@ func (om *OrderedMap[K, V]) Set(key K, value V) {
if om.m == nil {
om.m = make(map[K]V)
}
if om.mutex == nil {
Copy link
Contributor

@trim21 trim21 Apr 22, 2024

Choose a reason for hiding this comment

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

Doesn't look right, there is still a race condition here. Otherwise this if branch is a no-op

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we should likely instantiate this mutex on the New function.

@trim21
Copy link
Contributor

trim21 commented Apr 22, 2024

how about this: https://gist.github.com/trim21/0e5fd4ae16a393f471290d1d7e609a0c

(some tests need to be updated for this approach)

Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

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

Let's try to instantiate the mutex in a centralized manner on the New constructor.

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.

fatal error: concurrent map writes
3 participants