Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Catch cancellation exceptions - Fix TestTolerantSearch (#3393)

Houston Putman1490cf820233
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 1259bc85a7c..4535013a72b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -521,7 +522,13 @@ public class Http2SolrClient extends HttpSolrClientBase {
mdcCopyHelper.onBegin(null);
log.debug("response processing success");
future.complete(body);
- } catch (SolrClient.RemoteSolrException | SolrServerException e) {
+ } catch (CancellationException e) {
+ mdcCopyHelper.onBegin(null);
+ log.debug("response processing cancelled", e);
+ if (!future.isDone()) {
+ future.cancel(true);
+ }
+ } catch (Throwable e) {
mdcCopyHelper.onBegin(null);
log.debug("response processing failed", e);
future.completeExceptionally(e);
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
index 129ec8df8ca..e6e1cd44941 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -378,6 +379,7 @@ public class ExecutorUtil {
}
try {
command.run();
+ } catch (CancellationException ignored) {
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
throw t;