You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/05/18 12:50:44 UTC

[solr] branch main updated: SOLR-16190: Http2SolrClient should make sure to shutdown the executor (#848)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new b6665dfd3b9 SOLR-16190: Http2SolrClient should make sure to shutdown the executor (#848)
b6665dfd3b9 is described below

commit b6665dfd3b91aaadca06b9073c1e2a1cbf6ae50e
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Wed May 18 08:50:39 2022 -0400

    SOLR-16190: Http2SolrClient should make sure to shutdown the executor (#848)
---
 solr/CHANGES.txt                                      |  2 ++
 .../solr/client/solrj/impl/Http2SolrClient.java       | 19 +++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 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.java
index 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 up
       throw 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 this
     asyncTracker.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);