This is an automated email from the ASF dual-hosted git repository. krisden pushed a commit to branch branch_9_0 in repository https://gitbox.apache.org/repos/asf/solr.git
commit e4a622d0307d8730fa77d7108d8fa0926bae92a5 Author: Kevin Risden <[email protected]> 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 fdd3c615d80..6ae24ec85bf 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");
