Netty: Idle State Handler is not showing if channel is idle : <p><strong>My Requirement:</strong><br>
I want to detect if the channel is idle for reading for some amount of time and want to timeout based on that. My Netty client is sending request to 1000 servers.  </p>

<p><strong>Problem</strong>: My Netty Client is never showing that if there is any idle channel for sometime even if i am using some ips that will always timeout.
I doubt that i am not implementing IdleStateHandler correctly. I have tried decreasing read timeout of IdleStateHandler but no luck. I have spent hours in figuring this out. Any help will be really appreciated.<br>
So, below is my code:<br>
<strong>My Netty Client:</strong></p>

<pre><code>public void connect(final InetAddress remoteAddress){
        new Bootstrap()
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeout)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .group(eventLoopGroup)
            .channel(NioSocketChannel.class)
            .handler(httpNettyClientChannelInitializer)
            .connect(remoteAddress, serverPort)
            .addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) {
                        future.cancel(!future.isSuccess());
                    }
                });
    }
</code></pre>

<p><strong>My Netty Channel Initalizer:</strong></p>

<pre><code>public class HttpNettyClientChannelInitializer extends ChannelInitializer&lt;SocketChannel&gt; {

    private final Provider&lt;HttpNettyClientChannelHandler&gt; handlerProvider;
    private final int timeout;
    private int maxContentLength;

    @Inject
    public HttpNettyClientChannelInitializer(Provider&lt;HttpNettyClientChannelHandler&gt; handlerProvider,
            @Named("readResponseTimeout") int timeout, @Named("maxContentLength") int maxContentLength) {
        this.handlerProvider = handlerProvider;
        this.timeout = timeout;
        this.maxContentLength = maxContentLength;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) {
        ChannelPipeline pipelineNettyClientChannel = socketChannel.pipeline();
        pipelineNettyClientChannel.addLast("codec", new HttpClientCodec());
        pipelineNettyClientChannel.addLast("idleStateHandler", new IdleStateHandler(timeout,0,0, TimeUnit.MILLISECONDS));
        pipelineNettyClientChannel.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
        //handlerProvider.get() will provide new instance of channel handler
        pipelineNettyClientChannel.addLast("handler", handlerProvider.get());
    }

}
</code></pre>

<p><strong>My Netty Channel Handler</strong></p>

<pre><code> @ChannelHandler.Sharable
    public class HttpNettyClientChannelHandler extends SimpleChannelInboundHandler&lt;HttpObject&gt; {
      @Override
      public void channelActive(ChannelHandlerContext channelHandlerContext){...}

    @Override    
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpObject httpObject){...}

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
             if (evt instanceof IdleStateEvent) {
                 IdleStateEvent e = (IdleStateEvent) evt;
                 if (e.state() == IdleState.READER_IDLE) {
                     System.out.println("Idle channel");
                     ctx.close();
             }
         }
     }
}
</code></pre>
