Source:
<code>public void channelActive(ChannelHandlerContext ctx) throws Exception { if (LOG.isTraceEnabled()) { LOG.trace("Channel active {}", ctx.channel()); } final Channel channel = ctx.channel(); if (limitTotalNumberOfCnxns()) { ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1); channel.close(); return; } InetAddress addr = ((InetSocketAddress) channel.remoteAddress()).getAddress(); if (maxClientCnxns > 0 && getClientCnxnCount(addr) >= maxClientCnxns) { ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1); LOG.warn("Too many connections from - max is {}", addr, maxClientCnxns); channel.close(); return; } NettyServerCnxn cnxn = new NettyServerCnxn(channel, zkServer, NettyServerCnxnFactory.this); ctx.channel().attr(CONNECTION_ATTRIBUTE).set(cnxn); if (!cnxn.isZKServerRunning()) { <START> ServerMetrics.getMetrics().CNXN_CLOSED_WITHOUT_ZK_SERVER_RUNNING.add(1); <END> channel.close(); return; } if (handshakeThrottlingEnabled) { int outstandingHandshakesNum = outstandingHandshake.addAndGet(1); if (outstandingHandshakesNum > outstandingHandshakeLimit) { outstandingHandshake.addAndGet(-1); channel.close(); ServerMetrics.getMetrics().TLS_HANDSHAKE_EXCEEDED.add(1); } else { cnxn.setHandshakeState(HandshakeState.STARTED); } } if (secure) { SslHandler sslHandler = ctx.pipeline().get(SslHandler.class); Future<Channel> handshakeFuture = sslHandler.handshakeFuture(); handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn)); } else if (!shouldUsePortUnification) { allChannels.add(ctx.channel()); addCnxn(cnxn); } }</code><technical_language>Log event here? Logging is missing connection is rejected due maximum number of connections. useful add well</technical_language>

Target:
public void channelActive(ChannelHandlerContext ctx) throws Exception { if (LOG.isTraceEnabled()) { LOG.trace("Channel active {}", ctx.channel()); } final Channel channel = ctx.channel(); if (limitTotalNumberOfCnxns()) { ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1); channel.close(); return; } InetAddress addr = ((InetSocketAddress) channel.remoteAddress()).getAddress(); if (maxClientCnxns > 0 && getClientCnxnCount(addr) >= maxClientCnxns) { ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1); LOG.warn("Too many connections from - max is {}", addr, maxClientCnxns); channel.close(); return; } NettyServerCnxn cnxn = new NettyServerCnxn(channel, zkServer, NettyServerCnxnFactory.this); ctx.channel().attr(CONNECTION_ATTRIBUTE).set(cnxn); 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) { int outstandingHandshakesNum = outstandingHandshake.addAndGet(1); if (outstandingHandshakesNum > outstandingHandshakeLimit) { outstandingHandshake.addAndGet(-1); channel.close(); ServerMetrics.getMetrics().TLS_HANDSHAKE_EXCEEDED.add(1); } else { cnxn.setHandshakeState(HandshakeState.STARTED); } } if (secure) { SslHandler sslHandler = ctx.pipeline().get(SslHandler.class); Future<Channel> handshakeFuture = sslHandler.handshakeFuture(); handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn)); } else if (!shouldUsePortUnification) { allChannels.add(ctx.channel()); addCnxn(cnxn); } }