Skip to content

Conversation

davidkyle
Copy link
Member

If APM tracing is enabled the lost context meant the trace was never stopped and the span never released. After many calls to the action this small memory leak can amount to a substantial amount of memory potentially causing out of memory errors.

@davidkyle davidkyle added >bug :ml Machine learning auto-backport Automatically create backport pull requests when merged v9.2.0 v8.18.6 v9.0.6 v9.1.3 v8.19.3 labels Aug 15, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label Aug 15, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @davidkyle, I've created a changelog YAML for you.

@davidkyle
Copy link
Member Author

The thread context was meant to be preserved by this code

boolean added = queue.offer(contextHolder.preserveContext(command));

However there are 2 problems with that:

  1. If the request times out it the listener is called on a different thread

  2. The Inference action is always completed on the result processor thread

Anomaly detection uses the same ProcessWorkerExecutorService class but the thread context is preserved in that case because the same thread is always used.

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

I tested this locally and it is working. Dave and I chatted about how to create a end to end test for this. We'll follow up on that later.

@davidkyle davidkyle enabled auto-merge (squash) August 15, 2025 15:02
@davidkyle davidkyle merged commit 62c84a4 into elastic:main Aug 15, 2025
34 checks passed
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Aug 15, 2025
…32973)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Aug 15, 2025
…32973)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
9.0
9.1
8.19

davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Aug 15, 2025
…32973)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Aug 15, 2025
…32973)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
elasticsearchmachine pushed a commit that referenced this pull request Aug 15, 2025
…132997)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
elasticsearchmachine pushed a commit that referenced this pull request Aug 15, 2025
…132996)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
elasticsearchmachine pushed a commit that referenced this pull request Aug 15, 2025
…132998)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
elasticsearchmachine pushed a commit that referenced this pull request Aug 15, 2025
…132999)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
javanna pushed a commit to javanna/elasticsearch that referenced this pull request Aug 18, 2025
…32973)

Fixes a memory leak if APM tracing is enabled as the lost context meant the trace
was never closed and the span never released
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 >bug :ml Machine learning Team:ML Meta label for the ML team v8.18.6 v8.19.3 v9.0.6 v9.1.3 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants