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 4C583100A9 for ; Wed, 18 Sep 2013 02:08:55 +0000 (UTC) Received: (qmail 26457 invoked by uid 500); 18 Sep 2013 02:08:55 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 26438 invoked by uid 500); 18 Sep 2013 02:08:55 -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 26430 invoked by uid 99); 18 Sep 2013 02:08:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Sep 2013 02:08:55 +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; Wed, 18 Sep 2013 02:08:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DCE4323888A6; Wed, 18 Sep 2013 02:08:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1524275 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/ClientCnxn.java Date: Wed, 18 Sep 2013 02:08:33 -0000 To: commits@zookeeper.apache.org From: mahadev@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130918020833.DCE4323888A6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mahadev Date: Wed Sep 18 02:08:33 2013 New Revision: 1524275 URL: http://svn.apache.org/r1524275 Log: ZOOKEEPER-1751. ClientCnxn#run could miss the second ping or connection get dropped before a ping. (Jeffrey Zhong via mahadev) Modified: zookeeper/trunk/CHANGES.txt zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java Modified: zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1524275&r1=1524274&r2=1524275&view=diff ============================================================================== --- zookeeper/trunk/CHANGES.txt (original) +++ zookeeper/trunk/CHANGES.txt Wed Sep 18 02:08:33 2013 @@ -377,7 +377,10 @@ BUGFIXES: ZOOKEEPER-1664. Kerberos auth doesn't work with native platform GSS integration. (Boaz Kelmer via camille) ZOOKEEPER-1754. Read-only server allows to create znode (Rakesh R via fpj) - + + ZOOKEEPER-1751. ClientCnxn#run could miss the second ping or connection get + dropped before a ping. (Jeffrey Zhong via mahadev) + IMPROVEMENTS: ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports, Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=1524275&r1=1524274&r2=1524275&view=diff ============================================================================== --- zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java (original) +++ zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java Wed Sep 18 02:08:33 2013 @@ -1016,6 +1016,7 @@ public class ClientCnxn { clientCnxnSocket.updateLastSendAndHeard(); int to; long lastPingRwServer = System.currentTimeMillis(); + final int MAX_SEND_PING_INTERVAL = 10000; //10 seconds while (state.isAlive()) { try { if (!clientCnxnSocket.isConnected()) { @@ -1072,9 +1073,12 @@ public class ClientCnxn { + Long.toHexString(sessionId)); } if (state.isConnected()) { - int timeToNextPing = readTimeout / 2 - - clientCnxnSocket.getIdleSend(); - if (timeToNextPing <= 0) { + //1000(1 second) is to prevent race condition missing to send the second ping + //also make sure not to send too many pings when readTimeout is small + int timeToNextPing = readTimeout / 2 - clientCnxnSocket.getIdleSend() - + ((clientCnxnSocket.getIdleSend() > 1000) ? 1000 : 0); + //send a ping request either time is due or no packet sent out within MAX_SEND_PING_INTERVAL + if (timeToNextPing <= 0 || clientCnxnSocket.getIdleSend() > MAX_SEND_PING_INTERVAL) { sendPing(); clientCnxnSocket.updateLastSend(); } else {