频道丢弃后,Netty没有检测到超时

时间:2014-08-12 15:14:11

标签: java timeout netty heartbeat

奇怪的网络行为:获得了一个服务器频道,该频道需要心跳并通过IdleStateHandler捕获超时。建设如此:

@Override
public void initChannel(SocketChannel ch) throws Exception { 
    final ByteBuf delimiter = Unpooled.buffer(1); 
    long serverTimeout = 1000; 

    // Break input by newlines: 
    delimiter.writeByte('\n'); 
    ch.pipeline().addLast(new DelimiterBasedFrameDecoder(32768, delimiter)); 

    // Use UTF8 string: 
    ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8)); 

    // Timeout
    ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(serverTimeout, 0, 0, TimeUnit.MILLISECONDS)); 

    // Handle commands: 
    ch.pipeline().addLast("myHandler", new DBConnectionHandler()); 
}

如果客户端无法发送心跳,一切正常 - 触发并处理超时。但是,如果我粗暴地杀死客户端,相当于断开电缆,Netty不会触发超时。

使用Netty的超时异常(而不是空闲事件)具有相同的结果。

1 个答案:

答案 0 :(得分:0)

结果显示Netty确实识别了频道丢弃,它只是没有触发死信道的超时。要为相关频道上下文检测此调用channelHandlerContext.isRemoved()

相关问题