Skip to content

[9.2] Fix ArrayIndexOutOfBoundsException in fetch phase with partial results (#144385)#145003

Merged
elasticsearchmachine merged 1 commit intoelastic:9.2from
reugn:backport/9.2/pr-144385
Mar 26, 2026
Merged

[9.2] Fix ArrayIndexOutOfBoundsException in fetch phase with partial results (#144385)#145003
elasticsearchmachine merged 1 commit intoelastic:9.2from
reugn:backport/9.2/pr-144385

Conversation

@reugn
Copy link
Copy Markdown
Member

@reugn reugn commented Mar 26, 2026

Backports the following commits to 9.2:

elastic#144385)

When a search fetch phase times out on a shard with allow_partial_search_results: true, the coordinating node can hit an ArrayIndexOutOfBoundsException in SearchPhaseController.getHits() or SearchPhaseController.mergeSuggest(). This is caused by:

FetchPhaseDocsIterator.iterate() — on timeout, used System.arraycopy(searchHits, 0, partial, 0, i) to build the partial result. Because docs are iterated in doc-id order but placed at their original (score-sorted) positions, this copy produced a corrupted array. It included nulls at unfilled positions and dropped valid hits stored beyond index i. Fixed by replacing the arraycopy with a stripNulls method that returns a compact array of only the successfully fetched hits.

SearchPhaseController.getHits() / mergeSuggest() — the query phase promises N docs from a shard, but the fetch phase may return fewer after a timeout. The merge loop used a counter to index into the fetch result array without checking bounds, causing ArrayIndexOutOfBoundsException. Fixed by adding a bounds check that skips entries when the counter exceeds the available hits.
@reugn reugn added :Search Foundations/Search Catch all for Search Foundations >bug auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport priority:normal A label for assessing bug priority to be used by ES engineers Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch labels Mar 26, 2026
@elasticsearchmachine elasticsearchmachine merged commit 83bb982 into elastic:9.2 Mar 26, 2026
36 checks passed
@reugn reugn deleted the backport/9.2/pr-144385 branch March 26, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport >bug priority:normal A label for assessing bug priority to be used by ES engineers :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.8

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants