You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by sy...@apache.org on 2020/07/28 08:32:52 UTC

[zookeeper] branch branch-3.6 updated: ZOOKEEPER-3112: fix fd leak due to UnresolvedAddressException on connect

This is an automated email from the ASF dual-hosted git repository.

symat pushed a commit to branch branch-3.6
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.6 by this push:
     new 536593f  ZOOKEEPER-3112: fix fd leak due to UnresolvedAddressException on connect
536593f is described below

commit 536593f4d96b329fbf0fad6c45bbcb555f3ffebe
Author: Alexey.Saltanov <Al...@billing.ru>
AuthorDate: Tue Jul 28 08:29:28 2020 +0000

    ZOOKEEPER-3112: fix fd leak due to UnresolvedAddressException on connect
    
    SocketChannel.connect() can throw different kind of exceptions but ClientCnxnSocketNIO.connect() handles only IOException. This could lead to FD leak when socked is opened but is not connected. We should handle some additional exception classes and close the socket.
    
    Author: Alexey.Saltanov <Al...@billing.ru>
    
    Reviewers: Enrico Olivelli <eo...@apache.org>, Mate Szalay-Beko <sy...@apache.org>
    
    Closes #1410 from saltos/ZOOKEEPER-3112
    
    (cherry picked from commit 6a8728d98307f7d52cf6dbadb78149e01b1d0bf5)
    Signed-off-by: Mate Szalay-Beko <sy...@apache.org>
---
 .../src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java       | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java
index 1fe53a3..6cb125d 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java
@@ -26,6 +26,8 @@ import java.nio.ByteBuffer;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
+import java.nio.channels.UnresolvedAddressException;
+import java.nio.channels.UnsupportedAddressTypeException;
 import java.util.Iterator;
 import java.util.Queue;
 import java.util.Set;
@@ -266,7 +268,7 @@ public class ClientCnxnSocketNIO extends ClientCnxnSocket {
         SocketChannel sock = createSock();
         try {
             registerAndConnect(sock, addr);
-        } catch (IOException e) {
+        } catch (UnresolvedAddressException | UnsupportedAddressTypeException | SecurityException | IOException e) {
             LOG.error("Unable to open socket to {}", addr);
             sock.close();
             throw e;