Skip to content

fix: Stop HttpRemoteTaskRunner from launching tasks killed while pending - #20740

Merged
amaechler merged 2 commits into
apache:masterfrom
amaechler:hrtr-shutdown-pending-task
Oct 28, 2026
Merged

amaechler merged 2 commits into
apache:masterfrom
amaechler:hrtr-shutdown-pending-task

Conversation

@amaechler

Copy link
Copy Markdown
Contributor

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 calls TaskRunner.shutdown(), but HttpRemoteTaskRunner.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 in getPendingTasks().

shutdown() now removes a PENDING work item from pendingTaskIds under statusLock, then completes it with a FAILED status outside the lock, as taskComplete(...) requires. The item stays in tasks as COMPLETE, like a task a worker reported finished, and the next shutdown() call from TaskQueue removes 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 outside statusLock; completing it from shutdown() would race with that revert. If the worker starts the task, the next shutdown() call from TaskQueue finds it RUNNING and kills it on the worker. If the assignment fails, the item goes back to PENDING and the next shutdown() call completes it.

This is a regression from #13558, which stopped shutdown() from removing every work item from tasks so 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 httpRemote task runner (the default).


Key changed/added classes in this PR
  • HttpRemoteTaskRunner

This PR has:

  • been self-reviewed.
  • a release note entry in the PR description.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.

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 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Oct 28, 2026

@kfaraz kfaraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@amaechler

Copy link
Copy Markdown
Contributor Author

Yes, exactly. TaskQueue.shutdown() marks the entry complete but keeps it in activeTasks. The next syncFromStorage() (every druid.indexer.queue.storageSyncRate, 1 min by default) removes the entry.

I can open a follow-up issue for the failed-assignment case, as Frank bot mentioned above.

@amaechler
amaechler merged commit 63e3c24 into apache:master Oct 28, 2026
27 checks passed
@amaechler
amaechler deleted the hrtr-shutdown-pending-task branch October 28, 2026 15:57
@github-actions github-actions Bot added this to the 40.0.0 milestone Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approval Recommended Used when AI completes a review and reports no findings Area - Ingestion Bug Release Notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpRemoteTaskRunner can assign cancelled PENDING and PENDING_WORKER_ASSIGN tasks

3 participants