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 the yaml cache fully thread-safe #440

Merged
merged 2 commits into from
Nov 23, 2022
Merged

Conversation

mensfeld
Copy link
Contributor

@mensfeld mensfeld commented Nov 20, 2022

Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }

is prone to a race condition, thus the cache won't be fully thread safe if definitions are parsed in multiple threads.

This PR fixes that.

Ref: ruby-concurrency/concurrent-ruby#970

lib/dry/schema/messages/yaml.rb Outdated Show resolved Hide resolved
@mensfeld
Copy link
Contributor Author

specs dont seem to be related to this change

@mensfeld mensfeld requested a review from solnic November 22, 2022 09:30
Copy link
Member

@solnic solnic left a comment

Choose a reason for hiding this comment

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

I'm afraid spec failures are indeed caused by the fix, seems like cache isn't cleared properly between spec runs now.

@mensfeld
Copy link
Contributor Author

Got it. WIll look at this today.

@flash-gordon
Copy link
Member

I have main failing locally too, investigating

Finished in 10.7 seconds (files took 3.15 seconds to load)
3183 examples, 39 failures, 4 pending

@flash-gordon
Copy link
Member

main is green, merging

@flash-gordon flash-gordon merged commit 269362e into dry-rb:main Nov 23, 2022
@granthusbands
Copy link

@mensfeld You missed the ||= that you've fixed in pull requests for other projects.

@mensfeld
Copy link
Contributor Author

@granthusbands I did not miss it. I explicitly do not do it here to make the change small. I pointed out in the article that I wanted to keep the scope small because I do not know how given libs operate.

that you've fixed in pull requests for other projects.

Not exactly the same. In most cases, I fixed the internal ||=, not the external. Nonetheless you are right and feel free to create a PR :) @solnic should be happy

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.

4 participants