문제

I'm new to netty. Is this an expected behaviour?

A bit more detailed:

public class Test {
  public static void connect(){
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    Bootstrap bs = new Bootstrap();
    bs.group(workerGroup);
    bs.channel(NioSocketChannel.class);
    bs.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
    bs.handler( new ChannelInitializer<SocketChannel>(){
      @Override
      protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pl = ch.pipeline();
        pl.addLast("readTimeoutHandler", new ReadTimeoutHandler(1000,
          TimeUnit.MILLISECONDS));
          pl.addLast("framer", new DelimiterBasedFrameDecoder(
            16384, Delimiters.lineDelimiter()));
          pl.addLast("string-decoder", new StringDecoder());
          pl.addLast("handler", 
            new SimpleChannelInboundHandler<String> (String.class){
              @Override
              protected void channelRead0(ChannelHandlerContext ctx,
                String msg) throws Exception {
                System.out.println(msg);
              }
              @Override
              protected void exceptionCaught(ChannelHandlerContext ctx, 
                Throwable cause) throws Exception {
                if(cause instanceof ReadTimeoutException){
                  System.out.println("Timed out.");
                }
                ctx.close();
              }
          });
      }
    });
    bs.connect("127.0.0.1", 45001);
  }
}

This is just test case, so it might be a bit incorrect, pipeline ressembles my actual pipeline close enough though.

Basicly if I change EventLoopGroup initialization from NioEventLoopGroup to OioEventLoopGroup and bootstrap channel setup from bootstrap.channel(NioSocketChannel.class) to bootstrap.channel(OioSocketChannel.class) without touching anything else, ReadTimeoutHandler stops throwing ReadTimeoutExceptions.

도움이 되었습니까?

해결책

This was fixed in Netty 4.0.4.Final . Please upgrade, see [1].

[1] https://github.com/netty/netty/issues/1614

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top