You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ha...@apache.org on 2018/07/27 03:22:49 UTC

zookeeper git commit: ZOOKEEPER-3009: fix the related bugs in branch-3.4

Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.4 bd50b3bf1 -> fc346f2a0


ZOOKEEPER-3009: fix the related bugs in branch-3.4

The same problem that described in ZOOKEEPER-3009  also exists in branch-3.4, just as hanm said. I pull a new request to fix it. The patch just make the related code of 3.4 be same as 3.5. please check!!!

Author: lujiefsi <lu...@foxmail.com>
Author: lujie <lu...@foxmail.com>

Reviewers: Michael Han <ha...@apache.org>, Norbert Kalmar, Allan Lyu <fa...@apache.org>

Closes #544 from lujiefsi/ZOOKEEPER-3009-3.4


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

Branch: refs/heads/branch-3.4
Commit: fc346f2a0ce2df0a50eb601d7617d8dd6a7e6e69
Parents: bd50b3b
Author: lujiefsi <lu...@foxmail.com>
Authored: Thu Jul 26 20:22:45 2018 -0700
Committer: Michael Han <ha...@apache.org>
Committed: Thu Jul 26 20:22:45 2018 -0700

----------------------------------------------------------------------
 .../zookeeper/server/NIOServerCnxnFactory.java     | 17 ++++++++++++-----
 .../zookeeper/server/NettyServerCnxnFactory.java   | 10 +++++++---
 2 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fc346f2a/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
index d7581a4..67a8507 100644
--- a/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
+++ b/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
@@ -129,11 +129,14 @@ public class NIOServerCnxnFactory extends ServerCnxnFactory implements Runnable
         return ss.socket().getLocalPort();
     }
 
-    private void addCnxn(NIOServerCnxn cnxn) {
+    private void addCnxn(NIOServerCnxn cnxn) throws IOException {
         synchronized (cnxns) {
             cnxns.add(cnxn);
             synchronized (ipMap){
-                InetAddress addr = cnxn.sock.socket().getInetAddress();
+                InetAddress addr = cnxn.getSocketAddress();
+                if (addr == null) {
+                    throw new IOException("Socket of " + cnxn + " has been closed");
+                }
                 Set<NIOServerCnxn> s = ipMap.get(addr);
                 if (s == null) {
                     // in general we will see 1 connection from each
@@ -165,9 +168,13 @@ public class NIOServerCnxnFactory extends ServerCnxnFactory implements Runnable
             }
 
             synchronized (ipMap) {
-                Set<NIOServerCnxn> s =
-                        ipMap.get(cnxn.getSocketAddress());
-                s.remove(cnxn);
+                InetAddress addr = cnxn.getSocketAddress();
+                if (addr != null) {
+                    Set<NIOServerCnxn> s = ipMap.get(addr);
+                    if (s != null) {
+                        s.remove(cnxn);
+                    }
+            	}
             }
 
             unregisterConnection(cnxn);

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fc346f2a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
index a34a398..ddfe151 100644
--- a/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
+++ b/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
@@ -412,9 +412,13 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory {
             }
 
             synchronized (ipMap) {
-                Set<NettyServerCnxn> s =
-                        ipMap.get(cnxn.getSocketAddress());
-                s.remove(cnxn);
+                InetAddress addr = cnxn.getSocketAddress();
+                if (addr != null) {
+                    Set<NettyServerCnxn> s = ipMap.get(addr);
+                    if (s != null) {
+                        s.remove(cnxn);
+                    }
+            	}
             }
         }
     }