Bug #34343
closedForce cancel a paused task doesn't release the lock
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=2047683
Description of problem:
Still getting the following error after "force cancel" the paused task that was holding the locks.
-----------------------------------------------
Conflicts with tasks: https://satellite.example.com/foreman_tasks/tasks/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","errors":["Required lock is already taken by other running tasks.\nPlease inspect their state, fix their errors and resume them.
-----------------------------------------------
Steps to Reproduce:
1. Publish a content view and somehow make the task paused with error. Stop Pulp services in the middle of publish might help.
2. After that click "force cancel" the paused task in the Task page. Make sure the task status is set to stopped.
3. Publish the same content view again.
Actual results:
Fail with task conflict.
Expected results:
No conflict.
Additional info:
- Satellite 6.9
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-3.0.6/app/models/foreman_tasks/lock.rb
...
scope :active, -> { joins(:task).where('foreman_tasks_tasks.state != ?', :stopped) } <======= active scope got delete in 6.10
...
... # returns a scope of the locks colliding with this one
def colliding_locks
task_ids = task.self_and_parents.map(&:id)
colliding_locks_scope = Lock.active.where(Lock.arel_table[:task_id].not_in(task_ids)) <============ has Lock.active scope
colliding_locks_scope = colliding_locks_scope.where(name: name,
resource_id: resource_id,
resource_type: resource_type)
unless exclusive?
colliding_locks_scope = colliding_locks_scope.where(:exclusive => true)
end
colliding_locks_scope
end
- Satellite 6.10
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.5/app/models/foreman_tasks/lock.rb # returns a scope of the locks colliding with this one
def colliding_locks
task_ids = task.self_and_parents.map(&:id)
colliding_locks_scope = Lock.where(Lock.arel_table[:task_id].not_in(task_ids)) <========== Missing Lock.active scope
colliding_locks_scope.where(resource_id: resource_id,
resource_type: resource_type)
end