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/06 16:51:29 UTC

[solr] branch main updated: SOLR-16185: CloudSolrClientCacheTest leaks threads (#839)

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 26b29d4df41 SOLR-16185: CloudSolrClientCacheTest leaks threads (#839)
26b29d4df41 is described below

commit 26b29d4df41e4efe67576efd72a603818c42738e
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Fri May 6 12:51:25 2022 -0400

    SOLR-16185: CloudSolrClientCacheTest leaks threads (#839)
---
 .../solr/client/solrj/impl/CloudSolrClient.java     |  5 +++--
 .../client/solrj/impl/CloudSolrClientCacheTest.java | 21 ++++++++++++++-------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index a1f0222709b..7794818e89c 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -99,7 +99,7 @@ public abstract class CloudSolrClient extends SolrClient {
   // no of times collection state to be reloaded if stale state error is received
   private static final int MAX_STALE_RETRIES =
       Integer.parseInt(System.getProperty("cloudSolrClientMaxStaleRetries", "5"));
-  private Random rand = new Random();
+  private final Random rand = new Random();
 
   private final boolean updatesToLeaders;
   private final boolean directUpdatesToLeadersOnly;
@@ -304,7 +304,8 @@ public abstract class CloudSolrClient extends SolrClient {
   @Override
   public void close() throws IOException {
     if (this.threadPool != null && !this.threadPool.isShutdown()) {
-      this.threadPool.shutdown();
+      ExecutorUtil.shutdownAndAwaitTermination(this.threadPool);
+      this.threadPool = null;
     }
   }
 
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
index 4c9bebf369f..35c404d33a3 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
@@ -78,10 +78,11 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
 
     LBHttpSolrClient mockLbclient = getMockLbHttpSolrClient(responses);
     AtomicInteger lbhttpRequestCount = new AtomicInteger();
-    try (CloudSolrClient cloudClient =
-        new CloudSolrClientBuilder(getStateProvider(livenodes, refs))
-            .withLBHttpSolrClient(mockLbclient)
-            .build()) {
+    try (ClusterStateProvider clusterStateProvider = getStateProvider(livenodes, refs);
+        CloudSolrClient cloudClient =
+            new CloudSolrClientBuilder(clusterStateProvider)
+                .withLBHttpSolrClient(mockLbclient)
+                .build()) {
       livenodes.addAll(ImmutableSet.of("192.168.1.108:7574_solr", "192.168.1.108:8983_solr"));
       ClusterState cs =
           ClusterState.createFromJson(1, coll1State.getBytes(UTF_8), Collections.emptySet());
@@ -91,9 +92,15 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
           "request",
           o -> {
             int i = lbhttpRequestCount.incrementAndGet();
-            if (i == 1) return new ConnectException("TEST");
-            if (i == 2) return new SocketException("TEST");
-            if (i == 3) return new NoHttpResponseException("TEST");
+            if (i == 1) {
+              return new ConnectException("TEST");
+            }
+            if (i == 2) {
+              return new SocketException("TEST");
+            }
+            if (i == 3) {
+              return new NoHttpResponseException("TEST");
+            }
             return okResponse;
           });
       UpdateRequest update = new UpdateRequest().add("id", "123", "desc", "Something 0");