-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Make cache and values fully thread-safe #8951
Conversation
Not locking the default initialization can lead to race-conditions. Note: not sure if I should use one or two mutexes as I am not familiar with this code enough to make the judgment. ref: ruby-concurrency/concurrent-ruby#970
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mensfeld thanks for letting us know! Is the recommended pattern now to use compute_if_absent
?
@cache = Concurrent::Hash.new do |hash, key|
hash.compute_if_absent(key) { Concurrent::Hash.new }
end
@joshcooper if you want it to be thread-safe yes. |
@mensfeld could you update your PR to call |
@joshcooper not really. This PR is one year old. Feel free to close and apply the PR alongside other changes or ignore. Sorry but I no longer have puppet setup on my machine 🙏 |
Not locking the default initialization can lead to race-conditions. ref: ruby-concurrency/concurrent-ruby#970 Co-authored-by: Maciej Mensfeld <maciej@mensfeld.pl> resolves puppetlabs#8951
I added a new PR and added you as an author. Thanks for telling us about this issue! |
Not locking the default initialization can lead to race-conditions. I don't think we can switch to Concurrent::Map, and it's compute_if_absent method, because insertion order won't be maintained. So synchronize the long way. ref: ruby-concurrency/concurrent-ruby#970 Co-authored-by: Maciej Mensfeld <maciej@mensfeld.pl> resolves puppetlabs#8951
Not locking the default initialization can lead to race-conditions.
Note: not sure if I should use one or two mutexes as I am not familiar with this code enough to make the judgment.
ref: ruby-concurrency/concurrent-ruby#970