mirror of
https://github.com/yacy/yacy_search_server.git
synced 2026-10-25 05:54:15 +00:00
Merge pull request #809 from blinggnome/fix-remote-solr-httpclient-thread-leak-pr
Close owned remote Solr HTTP clients
This commit is contained in:
1 file changed
+9
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user