Acquire job row locks in a consistent order to prevent deadlocks (#89) - #90
Merged
Merged
Conversation
…ech#89) Pushing jobs whose unique keys already exist takes row locks through the ON CONFLICT ... DO UPDATE clause, and the worker's batched job updates take row locks too. When the two transactions overlapped and locked the same rows in a different order, Postgres killed one of them with DeadlockDetected, failing the push or the update batch. Both code paths now sort by the same key before touching rows: pushes insert in unique_key order (returning references in the caller's order), and the worker sorts its pending updates by (unique_key, id). A regression test replays the interleaving deterministically. Co-authored-by: audecasteigts <aude.casteigts@gmail.com>
luca-montaigut
force-pushed
the
branch-with-upgrades
branch
from
September 11, 2026 08:18
7acaac1 to
4fe6633
Compare
AudeCstg
marked this pull request as ready for review
September 11, 2026 08:29
|
Fixes #89. Taking over this PR from @AudeCstg, context in #58 (comment). It is rebased on What changes
ContextWe run Chancy in production at Ouihelp (8 queues, ~60 job types, cron on ~50 schedules) and have been running this fix since April with no deadlock since. Happy to adjust anything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR to follow changes used by tags