Merge "Fix race condition in refreshing "join" task state"

This commit is contained in:
Zuul 2018-11-15 20:30:33 +00:00 committed by Gerrit Code Review
commit a0c8da92dd

View File

@ -409,6 +409,17 @@ def _refresh_task_state(task_ex_id):
wf_ctrl = wf_base.get_controller(wf_ex, wf_spec) wf_ctrl = wf_base.get_controller(wf_ex, wf_spec)
with db_api.named_lock(task_ex.id):
# NOTE: we have to use this lock to prevent two (or more) such
# methods from changing task state and starting its action or
# workflow. Checking task state outside of this section is a
# performance optimization because locking is pretty expensive.
db_api.refresh(task_ex)
if (states.is_completed(task_ex.state)
or task_ex.state == states.RUNNING):
return
log_state = wf_ctrl.get_logical_task_state(task_ex) log_state = wf_ctrl.get_logical_task_state(task_ex)
state = log_state.state state = log_state.state