Skip to content

fix: Register background search tasks as children of parent - #5888

Open
Swiddis wants to merge 1 commit into
opensearch-project:mainfrom
Swiddis:fix/5647-zombie-tasks
Open

Swiddis wants to merge 1 commit into
opensearch-project:mainfrom
Swiddis:fix/5647-zombie-tasks

Conversation

@Swiddis

@Swiddis Swiddis commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Description

OpenSearch automatically propagates task cancellation to any child tasks, but we weren't actually marking our search tasks as children of the background search process. This led to zombie tasks being left behind on query cancellation.

Related Issues

Resolves #5647

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

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.

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
@github-actions

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

@Swiddis Swiddis added the bugFix label Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Remove redundant boolean flag

The restored flag is redundant since it's always set to true when cancellableTask !=
null. Simplify the logic by checking cancellableTask != null directly in the finally
block to reduce unnecessary state tracking.

opensearch/src/main/java/org/opensearch/sql/opensearch/storage/scan/BackgroundSearchScanner.java [134-146]

 private OpenSearchResponse backgroundSearch(ProfileContext ctx, OpenSearchRequest request) {
-  boolean restored = false;
   if (cancellableTask != null) {
     OpenSearchQueryManager.setCancellableTask(cancellableTask);
-    restored = true;
   }
   try {
     return QueryProfiling.withCurrentContext(ctx, () -> client.search(request));
   } finally {
-    if (restored) {
+    if (cancellableTask != null) {
       OpenSearchQueryManager.clearCancellableTask();
     }
   }
 }
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that the restored flag is redundant since it mirrors the cancellableTask != null check. However, this is a minor code style improvement that doesn't significantly impact functionality, correctness, or maintainability. The existing code is clear and the optimization is marginal.

Low

@Swiddis Swiddis changed the title fix: register background search tasks as children of parent fix: Register background search tasks as children of parent Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.86%. Comparing base (8e83f05) to head (c2db3b2).
⚠️ Report is 10 commits behind head on main.

❌ Your project check has failed because the head coverage (63.86%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5888      +/-   ##
============================================
+ Coverage     63.65%   63.86%   +0.21%     
- Complexity     9021     9097      +76     
============================================
  Files           959      962       +3     
  Lines         40823    41057     +234     
  Branches       4634     4671      +37     
============================================
+ Hits          25986    26223     +237     
+ Misses        13964    13956       -8     
- Partials        873      878       +5     
Flag Coverage Δ
sql-engine 63.86% <100.00%> (+0.21%) ⬆️

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.

This branch has not been deployed

No deployments
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] Zombie tasks on PPL cancellation

1 participant