Break the decode loop if decoder raises an exception to give a chance to close the connection to a user handler

- Fixes: #1161
This commit is contained in:
Trustin Lee 2013-03-16 18:28:58 +09:00
parent b186342f52
commit e3d10ad493
2 changed files with 19 additions and 15 deletions

View File

@ -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;
}
}

View File

@ -364,13 +364,13 @@ public abstract class ReplayingDecoder<S> 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<S> extends ByteToMessageDecoder {
} else {
ctx.fireExceptionCaught(new DecoderException(t));
}
} finally {
ctx.fireChannelInactive();
}
ctx.fireChannelInactive();
}
@Override
@ -458,6 +458,8 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
} else {
ctx.fireExceptionCaught(new DecoderException(t));
}
break;
}
}