Browse Source

ZOOKEEPER-1174. FD leak when network unreachable (Ted Dunning via camille)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1177042 13f79535-47bb-0310-9956-ffa450edef68
Camille Fournier 13 years ago
parent
commit
12f70403c6

+ 2 - 0
CHANGES.txt

@@ -17,6 +17,8 @@ BUGFIXES:
 
   ZOOKEEPER-1203. Zookeeper systest is missing Junit Classes
   (Prashant Gokhale via phunt)
+  
+  ZOOKEEPER-1174. FD leak when network unreachable (Ted Dunning via camille)
 
 IMPROVEMENTS:
 

+ 1 - 1
src/java/main/org/apache/zookeeper/ClientCnxn.java

@@ -1040,7 +1040,7 @@ public class ClientCnxn {
 
                     clientCnxnSocket.doTransport(to, pendingQueue, outgoingQueue);
 
-                } catch (Exception e) {
+                } catch (Throwable e) {
                     if (closing) {
                         if (LOG.isDebugEnabled()) {
                             // closing so this is expected

+ 13 - 3
src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java

@@ -189,9 +189,15 @@ public class ClientCnxnSocketNIO extends ClientCnxnSocket {
         sock.configureBlocking(false);
         sock.socket().setSoLinger(false, -1);
         sock.socket().setTcpNoDelay(true);
-        sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
-        if (sock.connect(addr)) {
-            sendThread.primeConnection();
+        try {            
+            sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
+            boolean immediateConnect = sock.connect(addr);
+            if (immediateConnect) {
+                sendThread.primeConnection();
+            }
+        } catch (IOException e) {
+            LOG.error("Unable to open socket to " + addr);
+            sock.close();
         }
         initialized = false;
 
@@ -304,4 +310,8 @@ public class ClientCnxnSocketNIO extends ClientCnxnSocket {
     synchronized void enableReadWriteOnly() {
         sockKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
     }
+
+    Selector getSelector() {
+        return selector;
+    }
 }

+ 3 - 5
src/java/main/org/apache/zookeeper/server/DataTree.java

@@ -183,7 +183,7 @@ public class DataTree {
     /**
      * converts a list of longs to a list of acls.
      *
-     * @param longs
+     * @param longVal
      *            the list of longs
      * @return a list of ACLs that map to longs
      */
@@ -594,7 +594,7 @@ public class DataTree {
     /**
      * If there is a quota set, return the appropriate prefix for that quota
      * Else return null
-     * @param The ZK path to check for quota
+     * @param path The ZK path to check for quota
      * @return Max quota prefix, or null if none
      */
     public String getMaxPrefixWithQuota(String path) {
@@ -933,9 +933,7 @@ public class DataTree {
      *
      * @param path
      *            the path to be used
-     * @param bytes
-     *            the long bytes
-     * @param count
+     * @param counts
      *            the int count
      */
     private void getCounts(String path, Counts counts) {