diff --git a/server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java b/server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java index ed7f2ae2cfe68..9dfff1d68b183 100644 --- a/server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java +++ b/server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java @@ -19,8 +19,6 @@ import org.opensearch.search.internal.SearchContext; import org.opensearch.search.profile.query.ProfileCollectorManager; import org.opensearch.search.query.QueryPhase.DefaultQueryPhaseSearcher; -import org.opensearch.tasks.TaskCancelledException; -import org.opensearch.transport.TransportException; import java.io.IOException; import java.util.LinkedList; @@ -92,17 +90,12 @@ private static boolean searchWithCollectorManager( if (re.getCause() instanceof ExecutionException || re.getCause() instanceof InterruptedException) { Throwable t = re.getCause(); if (t.getCause() != null) { - if (t.getCause() instanceof TransportException) { - throw (TransportException) t.getCause(); - } - if (t.getCause() instanceof TaskCancelledException) { - throw (TaskCancelledException) t.getCause(); - } + rethrow(t.getCause()); } } // Rethrow any unexpected exception types - throw re; + rethrow(re.getCause()); } if (searchContext.isSearchTimedOut()) { assert timeoutSet : "TimeExceededException thrown even though timeout wasn't set"; @@ -122,4 +115,9 @@ private static boolean searchWithCollectorManager( public AggregationProcessor aggregationProcessor(SearchContext searchContext) { return aggregationProcessor; } + + @SuppressWarnings("unchecked") + private static RuntimeException rethrow(Throwable throwable) throws T { + throw (T) throwable; // naively cast to unchecked exception + } }