Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E9B8A200C6B for ; Tue, 18 Apr 2017 01:44:33 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E878C160BAE; Mon, 17 Apr 2017 23:44:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3B5EB160BAB for ; Tue, 18 Apr 2017 01:44:33 +0200 (CEST) Received: (qmail 56810 invoked by uid 500); 17 Apr 2017 23:44:32 -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@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 56799 invoked by uid 99); 17 Apr 2017 23:44:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Apr 2017 23:44:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3E2C8DF9FD; Mon, 17 Apr 2017 23:44:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hanm@apache.org To: commits@zookeeper.apache.org Message-Id: <0bd6ac7465354778b0eee3856d9e11b3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: zookeeper git commit: ZOOKEEPER-2743: Netty connection leaks JMX connection bean. Date: Mon, 17 Apr 2017 23:44:32 +0000 (UTC) archived-at: Mon, 17 Apr 2017 23:44:34 -0000 Repository: zookeeper Updated Branches: refs/heads/branch-3.5 212201131 -> 434fecb11 ZOOKEEPER-2743: Netty connection leaks JMX connection bean. See https://issues.apache.org/jira/browse/ZOOKEEPER-2743 for details on the symptom and diagnostic. There are many ways of fixing this. For example we can enforce certain ordering of the close operations to eliminate the race condition however that would incur non trivial performance penalty as a result of synchronization. I think the solution in this patch is simple and effective as it observes that the bean unregister call is idempotent and the call itself is trivial so we just always unregister connection upon close the connection, to ensure the bean is unregistered regardless of the races. I've also stress tested this solution on internal Jenkins which indicates no failures of https://issues.apache.org/jira/browse/ZOOKEEPER-2707 for the past two days. A side note is NIO connection in theory would suffer the same problem however I am unable to reproduce the same racing with existing unit test. So I just leave NIO as it is, for now. Author: Michael Han Reviewers: Rakesh Radhakrishnan Closes #211 from hanm/ZOOKEEPER-2743 Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/434fecb1 Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/434fecb1 Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/434fecb1 Branch: refs/heads/branch-3.5 Commit: 434fecb1192c7c5968fa396ab217447716a44d7f Parents: 2122011 Author: Michael Han Authored: Mon Apr 10 10:19:34 2017 -0700 Committer: Michael Han Committed: Mon Apr 17 16:44:24 2017 -0700 ---------------------------------------------------------------------- .../main/org/apache/zookeeper/server/NettyServerCnxn.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/434fecb1/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java b/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java index cf5bd8a..142e916 100644 --- a/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java +++ b/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java @@ -87,6 +87,12 @@ public class NettyServerCnxn extends ServerCnxn { LOG.debug("close called for sessionid:0x" + Long.toHexString(sessionId)); } + + // ZOOKEEPER-2743: + // Always unregister connection upon close to prevent + // connection bean leak under certain race conditions. + factory.unregisterConnection(this); + synchronized(factory.cnxns){ // if this is not in cnxns then it's already closed if (!factory.cnxns.remove(this)) { @@ -111,7 +117,6 @@ public class NettyServerCnxn extends ServerCnxn { if (channel.isOpen()) { channel.close(); } - factory.unregisterConnection(this); } @Override