From e3d10ad493979c25904aee78bb12bf3151bbc920 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 16 Mar 2013 18:28:58 +0900 Subject: [PATCH] Break the decode loop if decoder raises an exception to give a chance to close the connection to a user handler - Fixes: #1161 --- .../handler/codec/ByteToMessageDecoder.java | 16 +++++++++------- .../netty/handler/codec/ReplayingDecoder.java | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java index cf53bf02ad..157d4b3b6e 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -82,12 +82,12 @@ public abstract class ByteToMessageDecoder @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - ByteBuf in = ctx.inboundByteBuffer(); - if (in.isReadable()) { - callDecode(ctx, in); - } - try { + ByteBuf in = ctx.inboundByteBuffer(); + if (in.isReadable()) { + callDecode(ctx, in); + } + if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, in))) { ctx.fireInboundBufferUpdated(); } @@ -97,9 +97,9 @@ public abstract class ByteToMessageDecoder } else { ctx.fireExceptionCaught(new DecoderException(t)); } + } finally { + ctx.fireChannelInactive(); } - - ctx.fireChannelInactive(); } protected void callDecode(ChannelHandlerContext ctx, ByteBuf in) { @@ -144,6 +144,8 @@ public abstract class ByteToMessageDecoder } else { ctx.fireExceptionCaught(new DecoderException(t)); } + + break; } } diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java index 9fa7603d33..d712d3ff70 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -364,13 +364,13 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - replayable.terminate(); - ByteBuf in = cumulation; - if (in.isReadable()) { - callDecode(ctx, in); - } - try { + replayable.terminate(); + ByteBuf in = cumulation; + if (in.isReadable()) { + callDecode(ctx, in); + } + if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, replayable))) { ctx.fireInboundBufferUpdated(); } @@ -383,9 +383,9 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { } else { ctx.fireExceptionCaught(new DecoderException(t)); } + } finally { + ctx.fireChannelInactive(); } - - ctx.fireChannelInactive(); } @Override @@ -458,6 +458,8 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { } else { ctx.fireExceptionCaught(new DecoderException(t)); } + + break; } }