Skip to content

Conversation

@drempapis
Copy link
Contributor

The current implementation of MutableSearchResponse.toAsyncSearchResponse() assumes that if finalResponse != null, the SearchResponse can always be retained. It enforces this by calling mustIncRef().

However, under concurrent execution, this assumption breaks down. One thread may be serializing a response while another (via AsyncSearchTask.close()) decrements the reference count. If decRef() drops the count to 0, the object is released. A later mustIncRef() will then fail, leading to assertion errors or use-after-release. This creates a race condition that can cause sporadic failures when fetching async search results, especially in the narrow window between task closure and document deletion.

This change replaces mustIncRef() with tryIncRef(). If the reference can no longer be retained, we safely set searchResponse = null and return a clear GONE error to the client. This avoids unsafe access to released resources and provides deterministic behavior in race scenarios.

@drempapis drempapis added >bug Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch :Search Foundations/Search Catch all for Search Foundations v9.2.0 labels Sep 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine
Copy link
Collaborator

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

@drempapis
Copy link
Contributor Author

Closing, a different approach was implemented #134359

@drempapis drempapis closed this Sep 11, 2025
@javanna javanna removed the v9.2.0 label Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants