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 @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
try {
ByteBuf in = ctx.inboundByteBuffer(); ByteBuf in = ctx.inboundByteBuffer();
if (in.isReadable()) { if (in.isReadable()) {
callDecode(ctx, in); callDecode(ctx, in);
} }
try {
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, in))) { if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, in))) {
ctx.fireInboundBufferUpdated(); ctx.fireInboundBufferUpdated();
} }
@ -97,10 +97,10 @@ public abstract class ByteToMessageDecoder
} else { } else {
ctx.fireExceptionCaught(new DecoderException(t)); ctx.fireExceptionCaught(new DecoderException(t));
} }
} } finally {
ctx.fireChannelInactive(); ctx.fireChannelInactive();
} }
}
protected void callDecode(ChannelHandlerContext ctx, ByteBuf in) { protected void callDecode(ChannelHandlerContext ctx, ByteBuf in) {
boolean wasNull = false; boolean wasNull = false;
@ -144,6 +144,8 @@ public abstract class ByteToMessageDecoder
} else { } else {
ctx.fireExceptionCaught(new DecoderException(t)); ctx.fireExceptionCaught(new DecoderException(t));
} }
break;
} }
} }

View File

@ -364,13 +364,13 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
try {
replayable.terminate(); replayable.terminate();
ByteBuf in = cumulation; ByteBuf in = cumulation;
if (in.isReadable()) { if (in.isReadable()) {
callDecode(ctx, in); callDecode(ctx, in);
} }
try {
if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, replayable))) { if (ctx.nextInboundMessageBuffer().unfoldAndAdd(decodeLast(ctx, replayable))) {
ctx.fireInboundBufferUpdated(); ctx.fireInboundBufferUpdated();
} }
@ -383,10 +383,10 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
} else { } else {
ctx.fireExceptionCaught(new DecoderException(t)); ctx.fireExceptionCaught(new DecoderException(t));
} }
} } finally {
ctx.fireChannelInactive(); ctx.fireChannelInactive();
} }
}
@Override @Override
protected void callDecode(ChannelHandlerContext ctx, ByteBuf buf) { protected void callDecode(ChannelHandlerContext ctx, ByteBuf buf) {
@ -458,6 +458,8 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
} else { } else {
ctx.fireExceptionCaught(new DecoderException(t)); ctx.fireExceptionCaught(new DecoderException(t));
} }
break;
} }
} }