[19.0] [FIX] queue_job: deadlock when the on fail hook writes the job's records - #1001
ivantodorovich wants to merge 1 commit into
Conversation
The failure is handled from a temporary cursor while the failed job's transaction still holds its locks: an on fail hook writing on the same records waited forever. Perform the job in a savepoint so that its locks are released when it fails.
d33125d to
c51fe59
Compare
UsmanGhias
left a comment
There was a problem hiding this comment.
Clean patch for OCA/queue.
Observations:
- SQL query correctly uses parameterized
%sarguments forcr.execute, maintaining clean injection safety.
Ready for testing on standard environments.
Regards,
Usman
https://usmanghias.co.uk
UsmanGhias
left a comment
There was a problem hiding this comment.
Great work on this PR! Fixing this deadlock scenario is a massive win for high-concurrency Odoo environments running heavy background queues.
Technically, wrapping the execution block inside env.cr.savepoint() is a clean way to drop row-level locks on failure while safely preserving the session-level advisory locks via queue_job_lock. I also appreciate how you structured the regression test using a separate cursor and a lock timeout to properly simulate the multi-connection concurrency issue without flakiness.
Just a small heads-up on the truncated test code at the end of the patch, but the logic itself is rock-solid. Excited to see this land in version 19!
Regards,
Usman
https://usmanghias.co.uk
When a job fails,
_runjobrecords the failure and calls theon_failhook from a temporary cursor, while the job's own transaction is still open.If the hook writes on a record the job wrote, it waits for the job's lock, which is only released after the hook. The job stays
startedforever -> deadlockThis PR runs the job inside a savepoint: when the job fails, rolling back the savepoint releases the locks it took. The job lock on
queue_job_lockwas taken before the savepoint, so it stays held.