Skip to content

Fix leaking bulk task on shard dispatch failure - #158112

Merged
mhl-b merged 6 commits into
elastic:mainfrom
mhl-b:fix-158019
Sep 3, 2026
Merged

mhl-b merged 6 commits into
elastic:mainfrom
mhl-b:fix-158019

Conversation

@mhl-b

@mhl-b mhl-b commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

fix #158019

NodeClient#executeLocally throws instead of notifying the listener when it cannot start a request at all: a cancelled parent task, oversized task headers, or an unresolvable action. BulkOperation#executeBulkShardRequest called it without a catch, so the ref acquired from bulkItemRequestCompleteRefCount for that shard request was never released and the bulk operation never completed. On the failure store redirect path the throw lands in a RefCountingRunnable delegate, which logs exception in delegate and swallows it, leaving the bulk task registered forever.

This PR completes the shard listener with the exception instead, which records the shard level failure, fails the shard's items and releases the ref. TransportAction#execute is exception-safe, so every way executeLocally can throw happens before the action runs and the listener is still uncompleted at that point.

@mhl-b mhl-b added :Distributed/Task Management Issues for anything around the Tasks API - both persistent and node level. >bug auto-backport Automatically create backport pull requests when merged labels Aug 29, 2026
@elasticsearchmachine elasticsearchmachine added v9.6.0 Team:Distributed Meta label for distributed team. labels Aug 29, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@mhl-b
mhl-b requested a review from DaveCTurner August 29, 2026 07:29
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

@DaveCTurner DaveCTurner 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.

I think I'd rather fix this with client.execute(), see comment.

Comment on lines +594 to +595
try {
client.executeLocally(TransportShardBulkAction.TYPE, bulkShardRequest, shardListener);

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.

Could we instead call client.execute()? That delegates into client.executeLocally() but will feed exceptions back to the listener as we want; it accepts a TaskCancelledException ok (see org.elasticsearch.client.internal.node.NodeClient#doExecute) while failing tests on other exceptions deemed to be unacceptable (see org.elasticsearch.client.internal.support.AbstractClient#execute).

@DaveCTurner

Copy link
Copy Markdown
Member

FWIW I've opened #158264 to address this more generally

@DaveCTurner

Copy link
Copy Markdown
Member

We're still discussing #158264 as it's a bigger change. I think we should fix this one spot to use client.execute() regardless, and soon. If it causes a conflict with #158264 then so be it.

@DaveCTurner DaveCTurner 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.

LGTM thanks @mhl-b

@mhl-b
mhl-b merged commit 9f12bba into elastic:main Sep 3, 2026
37 of 38 checks passed
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

💔 Backport failed

The backport operation could not be completed due to the following error:

There are no branches to backport to. Aborting.

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 158112

@mhl-b

mhl-b commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
✅ 9.5

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Sep 3, 2026
elasticsearchmachine pushed a commit that referenced this pull request Sep 3, 2026
elasticsearchmachine pushed a commit that referenced this pull request Sep 3, 2026
implicitly fixed by #158112

Closes #156929 Closes
#152925 Closes
#152291 Closes
#157763

(cherry picked from commit 25df1cc)

# Conflicts:
#	muted-tests.yml
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >bug :Distributed/Task Management Issues for anything around the Tasks API - both persistent and node level. Team:Distributed Meta label for distributed team. v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leak of bulk_session_timeout_tracking_action tasks with cancelled: true

3 participants