Apache Lucene open-source search software
SOLR-6146: Incorrect configuration such as wrong chroot in zk server address can cause CloudSolrServer to leak resources
Shalin Shekhar Mangar386d11c56336
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex def76680ebf..7a2e3037946 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -157,6 +157,9 @@ Bug Fixes* SOLR-6149: Specifying the query value without any index value does not work inAnalysis browser. (Aman Tandon, shalin)+* SOLR-6146: Incorrect configuration such as wrong chroot in zk server address can+ cause CloudSolrServer to leak resources. (Jessica Cheng, Varun Thacker, shalin)+Other Changes---------------------diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.javaindex ff3c5111bc7..e4a2afd618b 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java@@ -236,24 +236,33 @@ public class CloudSolrServer extends SolrServer {if (zkStateReader == null) {synchronized (this) {if (zkStateReader == null) {+ ZkStateReader zk = null;try {- ZkStateReader zk = new ZkStateReader(zkHost, zkClientTimeout,+ zk = new ZkStateReader(zkHost, zkClientTimeout,zkConnectTimeout);zk.createClusterStateWatchersAndUpdate();zkStateReader = zk;} catch (InterruptedException e) {Thread.currentThread().interrupt();+ if (zk != null) zk.close();throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"", e);} catch (KeeperException e) {+ if (zk != null) zk.close();throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"", e);} catch (IOException e) {+ if (zk != null) zk.close();throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"", e);} catch (TimeoutException e) {+ if (zk != null) zk.close();throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"", e);+ } catch (Exception e) {+ if (zk != null) zk.close();+ // do not wrap because clients may be relying on the underlying exception being thrown+ throw e;}}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.javaindex 5b3d87db929..82ce79df9a6 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrServerTest.java@@ -57,6 +57,7 @@ import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.ShardParams;import org.apache.solr.common.util.NamedList;+import org.apache.zookeeper.KeeperException;import org.junit.After;import org.junit.AfterClass;import org.junit.Before;@@ -359,4 +360,20 @@ public class CloudSolrServerTest extends AbstractFullDistribZkTestBase {}}+ public void testWrongZkChrootTest() throws MalformedURLException {+ CloudSolrServer server = null;+ try {+ server = new CloudSolrServer(zkServer.getZkAddress() + "/xyz/foo");+ server.setDefaultCollection(DEFAULT_COLLECTION);+ server.setZkClientTimeout(1000*60);+ server.connect();+ fail("Expected exception");+ } catch(SolrException e) {+ assertTrue(e.getCause() instanceof KeeperException);+ } finally {+ server.shutdown();+ }+ // see SOLR-6146 - this test will fail by virtue of the zkClient tracking performed+ // in the afterClass method of the base class+ }}