From 4b212b4b7f2f33277bcefcd68f3c678b2f9cff34 Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Mon, 20 Jun 2011 21:42:17 +0000 Subject: [PATCH] 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 --- .../src/org/apache/thrift/transport/THttpClient.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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(); -- 2.17.1