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

Make cache and values fully thread-safe #8951

Closed
wants to merge 1 commit into from

Conversation

mensfeld
Copy link

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

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
@mensfeld mensfeld requested a review from a team as a code owner November 21, 2022 11:17
@puppetlabs-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@CLAassistant
Copy link

CLAassistant commented Nov 21, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@joshcooper joshcooper left a 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 joshcooper added the bug Something isn't working label Nov 15, 2023
@mensfeld
Copy link
Author

@joshcooper if you want it to be thread-safe yes.

@joshcooper
Copy link
Contributor

@mensfeld could you update your PR to call compute_if_absent instead of creating a mutex?

@mensfeld
Copy link
Author

@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 🙏

joshcooper added a commit to joshcooper/puppet that referenced this pull request Nov 16, 2023
Not locking the default initialization can lead to race-conditions.

ref: ruby-concurrency/concurrent-ruby#970
Co-authored-by: Maciej Mensfeld <[email protected]>
resolves puppetlabs#8951
@joshcooper
Copy link
Contributor

joshcooper commented Nov 16, 2023

I added a new PR and added you as an author. Thanks for telling us about this issue!

@joshcooper joshcooper closed this Nov 16, 2023
joshcooper added a commit to joshcooper/puppet that referenced this pull request Nov 16, 2023
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 <[email protected]>
resolves puppetlabs#8951
@mensfeld mensfeld deleted the patch-1 branch November 17, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants