Apache Solr open-source search software
SOLR-16190: Http2SolrClient should make sure to shutdown the executor (#848)
Kevin Risdenb6665dfd3b91
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d389961f58b..c9e5b59b391 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -97,6 +97,8 @@ Other Changes* SOLR-16154: Event listeners submit through core container executor service instead of separate thread (Mike Drob, Kevin Risden)+* SOLR-16190: Http2SolrClient should make sure to shutdown the executor (Kevin Risden)+Build---------------------* SOLR-16053: Upgrade scriptDepVersions (Kevin Risden)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.javaindex a12d03c41f7..a10d578a6a3 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@@ -187,9 +187,9 @@ public class Http2SolrClient extends SolrClient {private HttpClient createHttpClient(Builder builder) {HttpClient httpClient;- BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(256, 256);executor = builder.executor;if (executor == null) {+ BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(256, 256);this.executor =new ExecutorUtil.MDCAwareThreadPoolExecutor(32, 256, 60, TimeUnit.SECONDS, queue, new SolrNamedThreadFactory("h2sc"));@@ -241,6 +241,7 @@ public class Http2SolrClient extends SolrClient {try {httpClient.start();} catch (Exception e) {+ close(); // make sure we clean upthrow new RuntimeException(e);}@@ -250,16 +251,18 @@ public class Http2SolrClient extends SolrClient {public void close() {// we wait for async requests, so far devs don't want to give sugar for thisasyncTracker.waitForComplete();- if (closeClient) {- try {+ try {+ if (closeClient) {httpClient.setStopTimeout(1000);httpClient.stop();- } catch (Exception e) {- throw new RuntimeException("Exception on closing client", e);+ httpClient.destroy();+ }+ } catch (Exception e) {+ throw new RuntimeException("Exception on closing client", e);+ } finally {+ if (shutdownExecutor) {+ ExecutorUtil.shutdownAndAwaitTermination(executor);}- }- if (shutdownExecutor) {- ExecutorUtil.shutdownAndAwaitTermination(executor);}assert ObjectReleaseTracker.release(this);