From 618a204cedd0ea2dc919a79e9114c2213bf82f6a Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Sat, 12 Oct 2013 21:26:54 +0000 Subject: [PATCH] SOLR-4327: HttpSolrServer can leak connections on errors. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1531596 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 2 ++ .../org/apache/solr/client/solrj/impl/HttpSolrServer.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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(); + } } } }