I have a question about netty server monitoring. I want to see how many open connections to the server are there, so to do that we have a code that has an atomic integer counter that is increased by 1 on ChannelInitializer.initChannel(..) method and decremented by 1 in closeFuture listener for that SocketChannel channel. For some reason that I can't figure out, it doesn't go to zero and stays positive under heavy load. I was hoping that maybe there is some better way of tracking these open channels?
@Override
protected void initChannel(SocketChannel channel) throws Exception {
currentConnections.incrementAndGet();
channel.closeFuture().addListener(f -> currentConnections.decrementAndGet());
}
UPDATE: So the number stays positive after clients stop sending traffic and disconnect.