accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [04/28] accumulo git commit: ACCUMULO-4317 Ensure the socket is closed on failure to set up a Thrift client
Date Tue, 21 Jun 2016 03:39:54 GMT
ACCUMULO-4317 Ensure the socket is closed on failure to set up a Thrift client

Signed-off-by: Josh Elser <elserj@apache.org>


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

Branch: refs/heads/1.8
Commit: 561f1893b9f239457e16c046702d8ba9df1474e2
Parents: d5ea00f
Author: Michiel Vanderlee <mastermikeyboy@gmail.com>
Authored: Mon Jun 20 18:09:37 2016 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Mon Jun 20 18:09:37 2016 -0400

----------------------------------------------------------------------
 .../accumulo/core/util/TTimeoutTransport.java   | 24 ++++++++++++++------
 .../apache/accumulo/core/util/ThriftUtil.java   |  8 ++++++-
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/561f1893/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java b/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
index 1eac8be..52a9a98 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
@@ -66,12 +66,22 @@ public class TTimeoutTransport {
   }
 
   public static TTransport create(SocketAddress addr, long timeoutMillis) throws IOException
{
-    Socket socket = SelectorProvider.provider().openSocketChannel().socket();
-    socket.setSoLinger(false, 0);
-    socket.setTcpNoDelay(true);
-    socket.connect(addr);
-    InputStream input = new BufferedInputStream(getInputStream(socket, timeoutMillis), 1024
* 10);
-    OutputStream output = new BufferedOutputStream(NetUtils.getOutputStream(socket, timeoutMillis),
1024 * 10);
-    return new TIOStreamTransport(input, output);
+    Socket socket = null;
+    try {
+      socket = SelectorProvider.provider().openSocketChannel().socket();
+      socket.setSoLinger(false, 0);
+      socket.setTcpNoDelay(true);
+      socket.connect(addr);
+      InputStream input = new BufferedInputStream(getInputStream(socket, timeoutMillis),
1024 * 10);
+      OutputStream output = new BufferedOutputStream(NetUtils.getOutputStream(socket, timeoutMillis),
1024 * 10);
+      return new TIOStreamTransport(input, output);
+    } catch (IOException e) {
+      try {
+        if (socket != null)
+          socket.close();
+      } catch (IOException ioe) {}
+
+      throw e;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/561f1893/core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java
index 29f7fb7..48ff3f2 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java
@@ -349,11 +349,17 @@ public class ThriftUtil {
    *          Socket timeout
    */
   private static TSocket createClient(SSLSocketFactory factory, String host, int port, int
timeout) throws TTransportException {
+    SSLSocket socket = null;
     try {
-      SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
+      socket = (SSLSocket) factory.createSocket(host, port);
       socket.setSoTimeout(timeout);
       return new TSocket(socket);
     } catch (Exception e) {
+      try {
+        if (socket != null)
+          socket.close();
+      } catch (IOException ioe) {}
+
       throw new TTransportException("Could not connect to " + host + " on port " + port,
e);
     }
   }


Mime
View raw message