Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BF45410F54 for ; Thu, 12 Sep 2013 17:31:35 +0000 (UTC) Received: (qmail 45857 invoked by uid 500); 12 Sep 2013 17:27:24 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 39934 invoked by uid 500); 12 Sep 2013 17:27:09 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 38043 invoked by uid 99); 12 Sep 2013 17:27:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 17:27:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 17:27:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3CA7C2388C9E; Thu, 12 Sep 2013 17:26:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@zookeeper.apache.org From: michim@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130912172641.3CA7C2388C9E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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(); + } + } +}