KYLIN-2814 fix HTTP connection may not be released in RestClient

Signed-off-by: Li Yang <liy...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/ae311b10
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/ae311b10
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/ae311b10

Branch: refs/heads/2622-2764
Commit: ae311b10e29f64c519140e4c02d903987981733a
Parents: 78543d6
Author: lichao <cha...@mobvoi.com>
Authored: Fri Aug 25 14:31:17 2017 +0800
Committer: Li Yang <liy...@apache.org>
Committed: Sun Sep 3 17:57:25 2017 +0800

----------------------------------------------------------------------
 .../java/org/apache/kylin/common/restclient/RestClient.java    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/ae311b10/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java 
b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
index 13490cb..b0ca5f7 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/restclient/RestClient.java
@@ -121,8 +121,9 @@ public class RestClient {
         String url = baseUrl + "/cache/" + entity + "/" + cacheKey + "/" + 
event;
         HttpPut request = new HttpPut(url);
 
+        HttpResponse response = null;
         try {
-            HttpResponse response = client.execute(request);
+            response = client.execute(request);
 
             if (response.getStatusLine().getStatusCode() != 200) {
                 String msg = EntityUtils.toString(response.getEntity());
@@ -131,6 +132,9 @@ public class RestClient {
         } catch (Exception ex) {
             throw new IOException(ex);
         } finally {
+            if (response != null) {
+                EntityUtils.consume(response.getEntity());
+            }
             request.releaseConnection();
         }
     }

Reply via email to