Repository navigation
Conversation
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
|
You can use Monitor instead of Mutex for re-entrancy.. though I'm surprised that's something we need to worry about. We can use an instance variable to hold the lock, instead of a class variable: everything we're protecting is class-local, so the lock should be too. Oh, was the re-entrancy across different classes? Trying to load a class's schema while we're already in the middle of loading the schema, even within a single thread, seems bad. You can find various uses of |
|
@matthewd I'm having a bit of difficulty conceptualising a test that would fail without this patch. Here is what I've been thinking for a test-case that would fail without this patch:
However, the problem is that this test-case won't work after the patch in this PR are applied. Since this PR introduces a mutex, the second thread will now hang and wait for the first thread to release the mutex - which would never happen as we have paused the first thread on a pre-determined location. |
|
@matthewd I've replaced the Mutex with a Monitor, as well as class variable with a class instance variable. The downside however is that private_class_method :load_schema_monitor
private_class_method :load_schema_monitor= |
This commit wraps `ActiveRecord::ModelSchema::ClassMethods#load_schema` in a Mutex to make it thread-safe. See #28589.
…ariable for `load_schema` mutex.
This PR wraps
ActiveRecord::ModelSchema::ClassMethods#load_schemain a Mutex to make it thread-safe. Closes #28589.Regarding tests, are there existing tests in Rails that test thread-safety from race-conditions that I can use as examples to write tests for this PR?