-
Notifications
You must be signed in to change notification settings - Fork 21
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
Race condition on updates in parallel with counter_cache or after_save #71
Comments
Thanks for the report. Will fix asap. |
* parallel-updates-bug: Describe the race condition context [skip ci] Fix #71 via configuration Make Race spec self-contained Add failing spec
Sorry for the delay. The issue emerges because Active Record counter cache issues an This could be fixed by overriding Active Record counter cache behaviour, to issue the update on the Further, given it is pointless to store changes to the counter cache in the history, please disable journaling on the counter cache column by using selective journaling, i.e.:
I have added a section in the README to mention the requirement. The spec is merged in b57ff40, and passes with the relevant |
Then we'd lose the purpose and benefit of the counter cache, but this was an example: the same happens when an after_save callback updates another parent object |
Let me check in the spec whether the The Callbacks problem is a completely different one, that will be researched separately. |
When a record has
after_save
hooks (or rails built-ins such as the counter cache) that update another object, and there are parallel updates that will affect the same object, there are regular failures with timeline consistency errors.The entire callback chain should be wrapped in a transaction or have an exclusive lock on the dependent object.
#70 has a spec to reproduce the issue
The text was updated successfully, but these errors were encountered: