Repository navigation
fix: Stop HttpRemoteTaskRunner from launching tasks killed while pending - #20740
Conversation
HttpRemoteTaskRunner.shutdown() only acted on RUNNING and COMPLETE work items. A task killed while PENDING or PENDING_WORKER_ASSIGN stayed in pendingTaskIds, so the pending task executor assigned it to the next free worker even though TaskQueue had already marked it FAILED and released its locks. It ran until the next storage sync dropped the queue entry and the management loop shut it down again. shutdown() now removes pending work items from pendingTaskIds under statusLock and completes them with a FAILED status outside the lock. The item stays in tasks as COMPLETE, so a worker that still starts an in-flight assignment gets the task killed through the existing COMPLETE case in taskAddedOrUpdated(), and the next shutdown() call removes it.
Completing a PENDING_WORKER_ASSIGN item from shutdown() races with the assigning thread, which may revert the item to PENDING outside statusLock and leave it PENDING with a completed future. shutdown() now only removes such an item from pendingTaskIds so it cannot be assigned again. If the worker starts the task, the next shutdown() call kills it on the worker; if the assignment fails, the item goes back to PENDING and the next shutdown() call completes it. Also checks the failure reason in the pending task test, makes its locals final and stops the task runner.
FrankChen021
left a comment
There was a problem hiding this comment.
🟡 Changes recommended
The PENDING_WORKER_ASSIGN shutdown path still has a cancellation handoff hole. shutdown() removes the task ID from pendingTaskIds but leaves the work item for the assigning thread; if runTaskOnWorker() then returns false because the worker is disabled, removed, or otherwise unavailable, the existing loop reverts the item to PENDING without re-adding the ID or completing the future. The task can remain in getPendingTasks() with incomplete cleanup until a later shutdown or storage sync.
Reviewed 2 of 2 changed files. The finding is in 1 file.
| Severity | Findings |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 1 |
| P3 | 0 |
| Total | 1 |
This is an automated review by Codex GPT-5.6-Luna(max)
After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.
kfaraz
left a comment
There was a problem hiding this comment.
Thanks for the find and the fix, @amaechler !
In the PR description, you mention that the next invocation of TaskQueue.shutdown() will finally clean up the pending task in some cases. Will this happen when the TaskQueue next does a sync with metadata storage?
|
Yes, exactly. I can open a follow-up issue for the failed-assignment case, as Frank bot mentioned above. |
Fixes #20298.
Description
A task killed while waiting for a task slot could still be launched by
HttpRemoteTaskRunner.TaskQueue.shutdown()marks the task FAILED, releases its locks and callsTaskRunner.shutdown(), butHttpRemoteTaskRunner.shutdown()ignored PENDING and PENDING_WORKER_ASSIGN work items. The pending task executor then assigned the task to the next free worker, where it ran until the next storage sync dropped the queue entry and the Overlord shut it down again. It also kept showing up ingetPendingTasks().shutdown()now removes a PENDING work item frompendingTaskIdsunderstatusLock, then completes it with a FAILED status outside the lock, astaskComplete(...)requires. The item stays intasksas COMPLETE, like a task a worker reported finished, and the nextshutdown()call fromTaskQueueremoves it.TaskQueue's callback for the FAILED future returns early because the entry is already complete.A PENDING_WORKER_ASSIGN item is only removed from
pendingTaskIds, so it cannot be assigned again. Its state belongs to the thread that is assigning it, which may revert it to PENDING outsidestatusLock; completing it fromshutdown()would race with that revert. If the worker starts the task, the nextshutdown()call fromTaskQueuefinds it RUNNING and kills it on the worker. If the assignment fails, the item goes back to PENDING and the nextshutdown()call completes it.This is a regression from #13558, which stopped
shutdown()from removing every work item fromtasksso that running tasks keep their completion callbacks.Release note
Fixed an issue where a task killed while waiting for a task slot could still be launched on a Middle Manager or Indexer when the Overlord uses the
httpRemotetask runner (the default).Key changed/added classes in this PR
HttpRemoteTaskRunnerThis PR has: