Skip to content

Commit

Permalink
ZOOKEEPER-2743: Netty connection leaks JMX connection bean.
Browse files Browse the repository at this point in the history
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 <hanm@apache.org>

Reviewers: Rakesh Radhakrishnan <rakeshr@apache.org>

Closes #211 from hanm/ZOOKEEPER-2743
  • Loading branch information
hanm committed Apr 10, 2017
1 parent d061f1b commit b3ef40b
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -87,6 +87,12 @@ public void close() {
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)) {
Expand All @@ -111,7 +117,6 @@ public void close() {
if (channel.isOpen()) {
channel.close();
}
factory.unregisterConnection(this);
}

@Override
Expand Down

0 comments on commit b3ef40b

Please sign in to comment.