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

Attempt fixing deadlocks by moving account stats update outside transaction #9437

Merged
merged 2 commits into from Dec 5, 2018

Conversation

Projects
None yet
2 participants
@ThibG
Copy link
Collaborator

ThibG commented Dec 5, 2018

increment_counter_caches may cause deadlocks when multiple jobs touch the same account.

From my understanding, this is because Status.create is always called inside a transaction, and increment_counter_caches will be called within that transaction, causing both a read and a write of that particular row within the same transaction.

This PR makes the callback executes after the transaction.

@ThibG ThibG force-pushed the ThibG:fixes/fix-deadlocks branch 2 times, most recently from 11f06e6 to b2410fd Dec 5, 2018

ThibG added some commits Dec 5, 2018

Use `update_column` instead of `update_attribute` in callback
`update_attribute` would normally cause callbacks to be called.
Called from a callback, it seems to stop further callbacks from executing.

`update_column` does the same work, but without calling callbacks or
preventing other callbacks from executing.

@ThibG ThibG force-pushed the ThibG:fixes/fix-deadlocks branch from d5e66b6 to 21105d6 Dec 5, 2018

@Gargron

Gargron approved these changes Dec 5, 2018

@Gargron Gargron merged commit 1a22eff into tootsuite:master Dec 5, 2018

11 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: check-i18n Your tests passed on CircleCI!
Details
ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.3 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.3 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: test-webui Your tests passed on CircleCI!
Details
codeclimate All good!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment