【发布时间】:2014-08-12 15:14:11
【问题描述】:
奇怪的 Netty 行为:获得了一个服务器通道,该通道需要检测信号并使用 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 的超时异常(而不是空闲事件)具有相同的结果。
【问题讨论】:
标签: java timeout netty heartbeat