From d3cc4f8b4ad97ddac1075f86bb0fda6a0fc1938a Mon Sep 17 00:00:00 2001 From: Simon Schmid Date: Fri, 12 Jul 2024 09:47:47 +0200 Subject: [PATCH] [bt#28115] queue_job: fix deadlock Fix a deadlock condition when there are dependent stored fields on `queue.job:state`. Example: - Sale-Order has a stored computed field which depends on job-state. - A job updates a sale-order record. - A exception is raised and in the final error-handling with a child cursor in https://github.com/OCA/queue/blob/c93a25366d2c51339ae4530a42eb7393bdc98b12/queue_job/controllers/main.py#L144 the job's state is updated, which also triggers an update in the sale order. Result is a deadlock. This commit adds a rollback in case of error during job execution, so that any locks are released. --- queue_job/controllers/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/queue_job/controllers/main.py b/queue_job/controllers/main.py index a93c644841..ee79f82205 100644 --- a/queue_job/controllers/main.py +++ b/queue_job/controllers/main.py @@ -32,11 +32,15 @@ def _try_perform_job(self, env, job): job.store() env.cr.commit() _logger.debug("%s started", job) + try: + job.perform() + # Triggers any stored computed fields before calling 'set_done' + # so that will be part of the 'exec_time' + env.flush_all() + except Exception: + env.cr.rollback() + raise - job.perform() - # Triggers any stored computed fields before calling 'set_done' - # so that will be part of the 'exec_time' - env.flush_all() job.set_done() job.store() env.flush_all()