-
Notifications
You must be signed in to change notification settings - Fork 792
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
Sprockets::CachedEnvironment is not thread-safe #772
Comments
What I need help with is whether this recursive call is intended and if we can avoid it. |
I've quickly tried to replace |
@byroot Could you help me with this? Maybe we can have a call or something to discuss the solutions. |
Note: we also need to care about the value being |
Sprockets::Cache::MemoryStore (https://github.com/rails/sprockets/blob/main/lib/sprockets/cache/memory_store.rb) has similar thread safety problems, and that matches the other backtraces in the TruffleRuby issues linked in the description. |
I have found a solution using I'm still interested to understand a bit better about Sprockets and whether it's OK to cache miss 2+ times for the same key in CachedEnvironment (was already the case). |
* This should help catching concurrency issues much faster. * Notably, the two issues of rails#772 reproduce by running the test suite on TruffleRuby. * Skip tests which do not pass yet on TrufffleRuby. oracle/truffleruby#2810
Yeah I think it's fine. |
Sprockets::CachedEnvironment is not thread-safe:
sprockets/lib/sprockets/cached_environment.rb
Lines 34 to 54 in 1276b43
Specifically it mutates Hash instances concurrently.
Expected behavior
It should work.
Actual behavior
It crashes with various thread safety-related issues.
For instance oracle/truffleruby#2808 and oracle/truffleruby#2804.
I tried the obvious approach of using
Concurrent::Map.new
+compute_if_absent
instead of a Hash in #771, but that doesn't work because Sprockets callsSprockets::CachedEnvironment#load
recursively (and on the same CachedEnvironment instance), e.g. (on CRuby):System configuration
Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS
Running the tests on TruffleRuby (
bundle exec rake
) on TruffleRuby reproduce this issue.Also the command-line above is an easy way to reproduce it on branch #771.
The text was updated successfully, but these errors were encountered: