Skip to content

Commit

Permalink
Merge pull request #17896 from mvdbeek/shorten_transaction
Browse files Browse the repository at this point in the history
[24.0] Fix deadlock that can occur when changing job state
  • Loading branch information
martenson authored Apr 3, 2024
2 parents ab2aa7d + 2594276 commit 4827ff8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,15 +1691,15 @@ def set_state(self, state: JobState) -> bool:
return False
session = object_session(self)
if session and self.id and state not in Job.finished_states:
# generate statement that will not revert DELETING or DELETED back to anything non-terminal
# Do not update if job is in a terminal state
rval = session.execute(
update(Job.table)
.where(Job.id == self.id, ~Job.state.in_((Job.states.DELETING, Job.states.DELETED)))
.where(Job.id == self.id, ~Job.state.in_((state, *Job.finished_states)))
.values(state=state)
)
with transaction(session):
session.commit()
if rval.rowcount == 1:
# Need to expire state since we just updated it, but ORM doesn't know about it.
session.expire(self, ["state"])
self.state_history.append(JobStateHistory(self))
return True
else:
Expand Down

0 comments on commit 4827ff8

Please sign in to comment.