diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxn.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxn.java index 269fcd942cc..673feca6bb8 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxn.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxn.java @@ -473,9 +473,13 @@ private void receiveMessage(ByteBuf message) { packetReceived(4 + bb.remaining()); ZooKeeperServer zks = this.zkServer; - if (zks == null || !zks.isRunning()) { + + if (zks == null) { throw new IOException("ZK down"); + } else if (!zks.isRunning()){ + LOG.debug("Zks not running but keep processing"); } + if (initialized) { // TODO: if zks.processPacket() is changed to take a ByteBuffer[], // we could implement zero-copy queueing. @@ -521,11 +525,11 @@ private void receiveMessage(ByteBuf message) { throw new IOException("Len error " + len); } ZooKeeperServer zks = this.zkServer; - if (zks == null || !zks.isRunning()) { - throw new IOException("ZK down"); + + if (zks != null && zks.isRunning()) { + // checkRequestSize will throw IOException if request is rejected + zks.checkRequestSizeWhenReceivingMessage(len); } - // checkRequestSize will throw IOException if request is rejected - zks.checkRequestSizeWhenReceivingMessage(len); bb = ByteBuffer.allocate(len); } } diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java index 0891021f35d..36fc10cc178 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java @@ -225,15 +225,6 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { NettyServerCnxn cnxn = new NettyServerCnxn(channel, zkServer, NettyServerCnxnFactory.this); ctx.channel().attr(CONNECTION_ATTRIBUTE).set(cnxn); - // Check the zkServer assigned to the cnxn is still running, - // close it before starting the heavy TLS handshake - if (!cnxn.isZKServerRunning()) { - LOG.warn("Zookeeper server is not running, close the connection before starting the TLS handshake"); - ServerMetrics.getMetrics().CNXN_CLOSED_WITHOUT_ZK_SERVER_RUNNING.add(1); - channel.close(); - return; - } - if (handshakeThrottlingEnabled) { // Favor to check and throttling even in dual mode which // accepts both secure and insecure connections, since @@ -264,9 +255,18 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { if (remoteAddress != null && !((InetSocketAddress) remoteAddress).getAddress().isLoopbackAddress()) { LOG.trace("NettyChannelHandler channelActive: remote={} local={}", remoteAddress, cnxn.getChannel().localAddress()); - zkServer.serverStats().incrementNonMTLSRemoteConnCount(); + + if (zkServer == null || zkServer.serverStats() == null) { + LOG.warn("zkServer is not initialized " + (zkServer == null ? "" : "for stats ") + " no remote connection stats update done"); + } else { + zkServer.serverStats().incrementNonMTLSRemoteConnCount(); + } } else { - zkServer.serverStats().incrementNonMTLSLocalConnCount(); + if (zkServer == null || zkServer.serverStats() == null) { + LOG.warn("zkServer is not initialized " + (zkServer == null ? "" : "for stats ") + " no local connection count stats update done" ); + } else { + zkServer.serverStats().incrementNonMTLSLocalConnCount(); + } } } }