Skip to content

[BugFix] Cancel the searches of an async PPL job when it is cancelled - #6012

Merged
ahkcs merged 1 commit into
opensearch-project:mainfrom
ahkcs:fix-6004-async-cancel-children
Dec 2, 2026
Merged

ahkcs merged 1 commit into
opensearch-project:mainfrom
ahkcs:fix-6004-async-cancel-children

Conversation

@ahkcs

@ahkcs ahkcs commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes #6004. DELETE /_plugins/_async_query/{id} on a running job returned CANCELLED, but the job's aggregation search kept running until it finished on its own.

Cause: the runner's cancel hook only called CancellableTask.cancel(), which marks the query task and nothing else.

  • A scan checks that flag before each page, so it stops after the page in flight.
  • An aggregation is one long search that never checks it, so it ran to the end.
  • The task manager could not cancel the search as a child either. The submit's transport task completed when the submit returned RUNNING, so the task manager no longer tracks it: _tasks shows no cluster:admin/opensearch/ppl task while the job runs. The search still names that task as its parent.

Fix: on cancel, mark the task as before, so no new search starts. Then send a CancelTasksRequest filtered on that parent task id, the same thing _tasks/_cancel?parent_task_id= does.

  • The request runs in a stashed thread context, as an internal call. A user allowed to delete their own job may not hold cluster task permissions.
  • If sending it fails, the failure is logged and the task is still marked cancelled.

Verification

A single node with 500k docs. The query source=demo-logs | where like(message, '%e%') | stats count() by span(@timestamp, 3h) is submitted with wait_for_completion_timeout: 0. Once its search task appears, the job is deleted, and _tasks?actions=indices:data/read/search is read afterwards:

+0.3 s +1.0 s +2.0 s
Before (main) running, cancelled: false running, 1,130 ms old gone (finished on its own)
After (3 runs) gone gone gone
Suite Result
TransportPPLQueryActionCancellationTest, 2 new tests pass. The new test checks the parent task id, the reason, and that the request is sent without the user's context. It fails without the fix.
:opensearch-sql-plugin:test, spotlessCheck pass
AsyncPPLSecurityIT (integTestWithSecurity), which includes deleting a running job through forwarding 2 / 2
AsyncPPLMultiNodeRoutingIT (asyncMultiNodeIT) 9 / 9
AsyncPPLQueryLifecycleIT 24 / 25. The one failure is the known parity_* flake on main: a wait=0 analysis error returns inline.

Related Issues

Resolves #6004

Check List

  • New functionality includes testing.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

DELETE /_plugins/_async_query/{id} only marked the query task cancelled. A
scan stops at its next page, but a search already running, such as an
aggregation, ran to the end after the client was told CANCELLED. The
submit's transport task has completed by then, so the task manager no
longer tracks it and cannot cancel its children; cancel them by their
parent task id instead, as _tasks/_cancel?parent_task_id= does.

Resolves opensearch-project#6004

Signed-off-by: Kai Huang <ahkcs@amazon.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@ahkcs ahkcs added the bugFix label Dec 1, 2026
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.49%. Comparing base (6beda2b) to head (0189e64).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6012   +/-   ##
=========================================
  Coverage     89.49%   89.49%           
  Complexity    12269    12269           
=========================================
  Files           980      980           
  Lines         42018    42018           
  Branches       4836     4836           
=========================================
  Hits          37604    37604           
  Misses         2940     2940           
  Partials       1474     1474           
Flag Coverage Δ
integration 69.95% <ø> (ø)
unit 76.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ahkcs
ahkcs merged commit 70c9b00 into opensearch-project:main Dec 2, 2026
42 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cancelling a running async PPL job leaves its aggregation search running

3 participants