Skip to content

Apache Lucene open-source search software

SOLR-4327: HttpSolrServer can leak connections on errors.

Mark Robert Miller618a204cedd0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 777011155af..cb0995ff7ef 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -182,6 +182,8 @@ Bug Fixes
* SOLR-5325: ZooKeeper connection loss can cause the Overseer to stop processing
commands. (Christine Poerschke, Mark Miller, Jessica Cheng)
+* SOLR-4327: HttpSolrServer can leak connections on errors. (Karl Wright, Mark Miller)
+
Other Changes
----------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
index f36c98e8fcb..7401bb82af1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
@@ -360,7 +360,7 @@ public class HttpSolrServer extends SolrServer {
InputStream respBody = null;
boolean shouldClose = true;
-
+ boolean success = false;
try {
// Execute the method.
final HttpResponse response = httpClient.execute(method);
@@ -404,6 +404,7 @@ public class HttpSolrServer extends SolrServer {
rsp.add("stream", respBody);
// Only case where stream should not be closed
shouldClose = false;
+ success = true;
return rsp;
}
@@ -462,6 +463,7 @@ public class HttpSolrServer extends SolrServer {
}
throw new RemoteSolrException(httpStatus, reason, null);
}
+ success = true;
return rsp;
} catch (ConnectException e) {
throw new SolrServerException("Server refused connection at: "
@@ -478,6 +480,9 @@ public class HttpSolrServer extends SolrServer {
try {
respBody.close();
} catch (Throwable t) {} // ignore
+ if (!success) {
+ method.abort();
+ }
}
}
}