### 背景 在看Qos模块的时候发现,pipeline中添加了IdleStateHandler来检测心跳,但是后面的Handler中,并没有发现处理心跳事件的地方,这个是不是漏掉了心跳的处理,超过5分钟断开连接呢? ``` @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 1) { return; } // read one byte to guess protocol final int magic = in.getByte(in.readerIndex()); ChannelPipeline p = ctx.pipeline(); p.addLast(new LocalHostPermitHandler(acceptForeignIp)); if (isHttp(magic)) { // no welcome output for http protocol if (welcomeFuture != null && welcomeFuture.isCancellable()) { welcomeFuture.cancel(false); } p.addLast(new HttpServerCodec()); p.addLast(new HttpObjectAggregator(1048576)); p.addLast(new HttpProcessHandler()); p.remove(this); } else { p.addLast(new LineBasedFrameDecoder(2048)); p.addLast(new StringDecoder(CharsetUtil.UTF_8)); p.addLast(new StringEncoder(CharsetUtil.UTF_8)); p.addLast(new IdleStateHandler(0, 0, 5 * 60)); //心跳检测 p.addLast(new TelnetProcessHandler()); p.remove(this); } }```
Activity
gudegg commentedon Jan 7, 2019
netty已经帮你实现了;可以看下IdleStateHandler的实现,里面有定时器
lkj41110 commentedon Jan 8, 2019
IdleStateHandler里面也只是触发userEventTriggered事件,但是在qos里好像没有找到相关的userEventTriggered处理
CrazyHZM commentedon Jan 8, 2019
你的意思是需要对检测到断开后加上处理对吗
carryxyh commentedon Jan 8, 2019
@lkj41110
这个地方好像确实是没加。提交个PR加上吧,idle的情况下直接close掉channel即可。
qos heart question fix apache#3165
Qos heart (apache#3170)
Merge master branch to 3.x dev branch (#3718)