Commit 1129baf3 authored by Michi Mutsuzaki's avatar Michi Mutsuzaki
Browse files

ZOOKEEPER-1839. Deadlock in NettyServerCnxn (Rakesh R via michim)


git-svn-id: https://svn.apache.org/repos/asf/zookeeper/branches/branch-3.4@1551112 13f79535-47bb-0310-9956-ffa450edef68
parent ea7a2c5e
...@@ -186,6 +186,8 @@ BUGFIXES: ...@@ -186,6 +186,8 @@ BUGFIXES:
ZOOKEEPER-1837. Fix JMXEnv checks (potential race conditions) ZOOKEEPER-1837. Fix JMXEnv checks (potential race conditions)
(Germán Blanco via fpj) (Germán Blanco via fpj)
ZOOKEEPER-1839. Deadlock in NettyServerCnxn (Rakesh R via michim)
IMPROVEMENTS: IMPROVEMENTS:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java ZOOKEEPER-1564. Allow JUnit test build with IBM Java
......
...@@ -108,12 +108,12 @@ public class NettyServerCnxn extends ServerCnxn { ...@@ -108,12 +108,12 @@ public class NettyServerCnxn extends ServerCnxn {
.getRemoteAddress()).getAddress()); .getRemoteAddress()).getAddress());
s.remove(this); s.remove(this);
} }
if (channel.isOpen()) {
channel.close();
}
factory.unregisterConnection(this);
} }
if (channel.isOpen()) {
channel.close();
}
factory.unregisterConnection(this);
} }
@Override @Override
......
...@@ -260,20 +260,22 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory { ...@@ -260,20 +260,22 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory {
LOG.debug("closeAll()"); LOG.debug("closeAll()");
} }
NettyServerCnxn[] allCnxns = null;
synchronized (cnxns) { synchronized (cnxns) {
// got to clear all the connections that we have in the selector allCnxns = cnxns.toArray(new NettyServerCnxn[cnxns.size()]);
for (NettyServerCnxn cnxn : cnxns.toArray(new NettyServerCnxn[cnxns.size()])) { }
try { // got to clear all the connections that we have in the selector
cnxn.close(); for (NettyServerCnxn cnxn : allCnxns) {
} catch (Exception e) { try {
LOG.warn("Ignoring exception closing cnxn sessionid 0x" cnxn.close();
+ Long.toHexString(cnxn.getSessionId()), e); } catch (Exception e) {
} LOG.warn("Ignoring exception closing cnxn sessionid 0x"
+ Long.toHexString(cnxn.getSessionId()), e);
} }
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("allChannels size:" + allChannels.size() LOG.debug("allChannels size:" + allChannels.size() + " cnxns size:"
+ " cnxns size:" + cnxns.size()); + allCnxns.length);
} }
} }
...@@ -282,17 +284,18 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory { ...@@ -282,17 +284,18 @@ public class NettyServerCnxnFactory extends ServerCnxnFactory {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("closeSession sessionid:0x" + sessionId); LOG.debug("closeSession sessionid:0x" + sessionId);
} }
NettyServerCnxn[] allCnxns = null;
synchronized (cnxns) { synchronized (cnxns) {
for (NettyServerCnxn cnxn : cnxns.toArray(new NettyServerCnxn[cnxns.size()])) { allCnxns = cnxns.toArray(new NettyServerCnxn[cnxns.size()]);
if (cnxn.getSessionId() == sessionId) { }
try { for (NettyServerCnxn cnxn : allCnxns) {
cnxn.close(); if (cnxn.getSessionId() == sessionId) {
} catch (Exception e) { try {
LOG.warn("exception during session close", e); cnxn.close();
} } catch (Exception e) {
break; LOG.warn("exception during session close", e);
} }
break;
} }
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment