zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject svn commit: r1522673 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
Date Thu, 12 Sep 2013 17:26:41 GMT
Author: michim
Date: Thu Sep 12 17:26:40 2013
New Revision: 1522673

URL: http://svn.apache.org/r1522673
Log:
ZOOKEEPER-1750. Race condition producing NPE in NIOServerCnxn.toString (Rakesh R via michim)

Added:
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1522673&r1=1522672&r2=1522673&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Thu Sep 12 17:26:40 2013
@@ -93,6 +93,10 @@ BUGFIXES:
   ZOOKEEPER-1448: Node+Quota creation in transaction log can crash leader startup (Botond
Hejj via fpj) 
  
   ZOOKEEPER-1664. Kerberos auth doesn't work with native platform GSS integration. (Boaz
Kelmer via camille) 
+
+  ZOOKEEPER-1750. Race condition producing NPE in NIOServerCnxn.toString
+  (Rakesh R via michim)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1564. Allow JUnit test build with IBM Java

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=1522673&r1=1522672&r2=1522673&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
Thu Sep 12 17:26:40 2013
@@ -60,7 +60,7 @@ public class NIOServerCnxn extends Serve
 
     NIOServerCnxnFactory factory;
 
-    SocketChannel sock;
+    final SocketChannel sock;
 
     private final SelectionKey sk;
 
@@ -132,7 +132,7 @@ public class NIOServerCnxn extends Serve
             */
            sock.configureBlocking(true);
            if (bb != ServerCnxnFactory.closeConn) {
-               if (sock != null) {
+               if (sock.isOpen()) {
                    sock.write(bb);
                }
                packetSent();
@@ -206,7 +206,7 @@ public class NIOServerCnxn extends Serve
 
     void doIO(SelectionKey k) throws InterruptedException {
         try {
-            if (sock == null) {
+            if (sock.isOpen() == false) {
                 LOG.warn("trying to do i/o on a null socket for session:0x"
                          + Long.toHexString(sessionId));
 
@@ -990,7 +990,7 @@ public class NIOServerCnxn extends Serve
      * Close resources associated with the sock of this cnxn. 
      */
     private void closeSock() {
-        if (sock == null) {
+        if (sock.isOpen() == false) {
             return;
         }
 
@@ -1039,7 +1039,6 @@ public class NIOServerCnxn extends Serve
                 LOG.debug("ignoring exception during socketchannel close", e);
             }
         }
-        sock = null;
     }
     
     private final static byte fourBytes[] = new byte[4];
@@ -1136,7 +1135,7 @@ public class NIOServerCnxn extends Serve
 
     @Override
     public InetSocketAddress getRemoteSocketAddress() {
-        if (sock == null) {
+        if (sock.isOpen() == false) {
             return null;
         }
         return (InetSocketAddress) sock.socket().getRemoteSocketAddress();

Added: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java?rev=1522673&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
(added)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/NIOServerCnxnTest.java
Thu Sep 12 17:26:40 2013
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.server;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.test.ClientBase;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NIOServerCnxnTest extends ClientBase {
+    private static final Logger LOG = LoggerFactory
+            .getLogger(NIOServerCnxnTest.class);
+    /**
+     * Test operations on ServerCnxn after socket closure.
+     */
+    @Test(timeout = 60000)
+    public void testOperationsAfterCnxnClose() throws IOException,
+            InterruptedException, KeeperException {
+        final ZooKeeper zk = createClient();
+
+        final String path = "/a";
+        try {
+            // make sure zkclient works
+            zk.create(path, "test".getBytes(), Ids.OPEN_ACL_UNSAFE,
+                    CreateMode.PERSISTENT);
+            Assert.assertNotNull("Didn't create znode:" + path,
+                    zk.exists(path, false));
+            // Defaults ServerCnxnFactory would be instantiated with
+            // NIOServerCnxnFactory
+            Assert.assertTrue(
+                    "Didn't instantiate ServerCnxnFactory with NIOServerCnxnFactory!",
+                    serverFactory instanceof NIOServerCnxnFactory);
+            Iterable<ServerCnxn> connections = serverFactory.getConnections();
+            for (ServerCnxn serverCnxn : connections) {
+                serverCnxn.close();
+                try {
+                    serverCnxn.toString();
+                } catch (Exception e) {
+                    LOG.error("Exception while getting connection details!", e);
+                    Assert.fail("Shouldn't throw exception while "
+                            + "getting connection details!");
+                }
+            }
+        } finally {
+            zk.close();
+        }
+    }
+}



Mime
View raw message