From 751ad99bb4627f5652ff369e18ecff8d3d7898f1 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 18 Dec 2024 13:00:24 -0500 Subject: [PATCH] Fix query timeout handling by checking searchContext.isSearchTimedOut() Signed-off-by: Andriy Redko --- CHANGELOG.md | 1 + .../org/opensearch/search/internal/ContextIndexSearcher.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f439e48ecab7..e589992a907b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Skip remote-repositories validations for node-joins when RepositoriesService is not in sync with cluster-state ([#16763](https://github.com/opensearch-project/OpenSearch/pull/16763)) - Fix _list/shards API failing when closed indices are present ([#16606](https://github.com/opensearch-project/OpenSearch/pull/16606)) - Fix remote shards balance ([#15335](https://github.com/opensearch-project/OpenSearch/pull/15335)) +- Fix query timeout handling by checking searchContext.isSearchTimedOut() ([#16882](https://github.com/opensearch-project/OpenSearch/pull/16882)) ### Security diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index aa8212e8dad69..fe66a203d10e4 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -305,6 +305,10 @@ protected void search(List leaves, Weight weight, Collector c */ @Override protected void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collector) throws IOException { + // If search is already flagged as timed out, do not continue + if (searchContext.isSearchTimedOut()) { + return; + } // Check if at all we need to call this leaf for collecting results. if (canMatch(ctx) == false) {