From: Bryan Duxbury Date: Mon, 20 Jun 2011 21:42:17 +0000 (+0000) Subject: THRIFT-1211. java: When using THttpClient, non 200 responses leave the connection... X-Git-Tag: 0.7.0~60 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=4b212b4b7f2f33277bcefcd68f3c678b2f9cff34;p=common%2Fthrift.git THRIFT-1211. java: When using THttpClient, non 200 responses leave the connection open This patch reorders the code so that we can close the connection in the case of an error. Patch: Mathias Herberts git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1137794 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/java/src/org/apache/thrift/transport/THttpClient.java b/lib/java/src/org/apache/thrift/transport/THttpClient.java index 550d76d1..b16da685 100644 --- a/lib/java/src/org/apache/thrift/transport/THttpClient.java +++ b/lib/java/src/org/apache/thrift/transport/THttpClient.java @@ -233,6 +233,13 @@ public class THttpClient extends TTransport { HttpResponse response = this.client.execute(this.host, post); int responseCode = response.getStatusLine().getStatusCode(); + + // + // Retrieve the inputstream BEFORE checking the status code so + // resources get freed in the finally clause. + // + + is = response.getEntity().getContent(); if (responseCode != HttpStatus.SC_OK) { throw new TTransportException("HTTP Response code: " + responseCode); @@ -245,8 +252,6 @@ public class THttpClient extends TTransport { // Proceeding differently might lead to exhaustion of connections and thus // to app failure. - is = response.getEntity().getContent(); - byte[] buf = new byte[1024]; ByteArrayOutputStream baos = new ByteArrayOutputStream();