Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Close owned remote Solr HTTP clients

blinggnome99b14e964732
diff --git a/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java b/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java
index ee2303312..616524eef 100644
--- a/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java
+++ b/source/net/yacy/cora/federate/solr/instance/RemoteInstance.java
@@ -101,6 +101,9 @@ public class RemoteInstance implements SolrInstance {
/** HTTP client used to request the Solr server */
private final HttpClient client;
+
+ /** When true, this instance owns the HTTP client and must close it. */
+ private final boolean closeClientOnClose;
/** Default Solr core name */
private final String defaultCoreName;
@@ -251,9 +254,11 @@ public class RemoteInstance implements SolrInstance {
}
if (solraccount.length() > 0) {
this.client = buildCustomHttpClient(timeout, u, solraccount, solrpw, host, trustSelfSignedOnAuthenticatedServer, maxBytesPerResponse);
+ this.closeClientOnClose = false;
} else if(u.isHTTPS()){
/* Here we must trust self-signed certificates as most peers with SSL enabled use such certificates */
this.client = buildCustomHttpClient(timeout, u, solraccount, solrpw, host, true, maxBytesPerResponse);
+ this.closeClientOnClose = false;
} else {
/* Build a http client using the Solr utils as in the HttpSolrClient constructor implementation.
* The main difference is that a shared connection manager is used (configured in the buildConnectionManager() function) */
@@ -269,6 +274,7 @@ public class RemoteInstance implements SolrInstance {
this.client = HttpClientUtil.createClient(params);
+ this.closeClientOnClose = true;
if(this.client instanceof org.apache.http.impl.client.DefaultHttpClient) {
if(this.client.getParams() != null) {
/* Set the maximum time to get a connection from the shared connections pool */
@@ -561,6 +567,9 @@ public class RemoteInstance implements SolrInstance {
} catch (final IOException ignored) {
}
}
+ if (this.closeClientOnClose) {
+ HttpClientUtil.close(this.client);
+ }
}
/**