From 99b14e964732c31981dc15d2c5c7246812f2678c Mon Sep 17 00:00:00 2001 From: blinggnome <220555374+blinggnome@users.noreply.github.com> Date: Thu, 13 Aug 2026 19:32:53 -0600 Subject: [PATCH] Close owned remote Solr HTTP clients --- .../yacy/cora/federate/solr/instance/RemoteInstance.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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); + } } /**