[#976] Fix exception which will be raised by ChannelInboundHandler.discardInboundReadBytes() and ChannelOutboundHandler.discardOutboundReadBytes() if the handler remove it self from the pipeline

This commit is contained in:
Norman Maurer 2013-01-23 07:27:00 +01:00
parent a25f7fa2e5
commit 3f72add89a
2 changed files with 5 additions and 3 deletions

View File

@ -80,6 +80,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
private Runnable invokeFreeInboundBuffer0Task; private Runnable invokeFreeInboundBuffer0Task;
private Runnable invokeFreeOutboundBuffer0Task; private Runnable invokeFreeOutboundBuffer0Task;
private Runnable invokeRead0Task; private Runnable invokeRead0Task;
boolean removed;
DefaultChannelHandlerContext( DefaultChannelHandlerContext(
DefaultChannelPipeline pipeline, EventExecutorGroup group, DefaultChannelPipeline pipeline, EventExecutorGroup group,
@ -1084,7 +1085,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
} catch (Throwable t) { } catch (Throwable t) {
pipeline.notifyHandlerException(t); pipeline.notifyHandlerException(t);
} finally { } finally {
if (handler instanceof ChannelInboundByteHandler && !isInboundBufferFreed()) { if (!removed && handler instanceof ChannelInboundByteHandler && !isInboundBufferFreed()) {
try { try {
((ChannelInboundByteHandler) handler).discardInboundReadBytes(this); ((ChannelInboundByteHandler) handler).discardInboundReadBytes(this);
} catch (Throwable t) { } catch (Throwable t) {
@ -1424,7 +1425,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
} catch (Throwable t) { } catch (Throwable t) {
pipeline.notifyHandlerException(t); pipeline.notifyHandlerException(t);
} finally { } finally {
if (handler instanceof ChannelOutboundByteHandler && !isOutboundBufferFreed()) { if (!removed && handler instanceof ChannelOutboundByteHandler && !isOutboundBufferFreed()) {
try { try {
((ChannelOutboundByteHandler) handler).discardOutboundReadBytes(this); ((ChannelOutboundByteHandler) handler).discardOutboundReadBytes(this);
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -599,7 +599,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
} }
} }
private void callAfterRemove(final ChannelHandlerContext ctx) { private void callAfterRemove(final DefaultChannelHandlerContext ctx) {
final ChannelHandler handler = ctx.handler(); final ChannelHandler handler = ctx.handler();
// Notify the complete removal. // Notify the complete removal.
@ -622,6 +622,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
} else { } else {
freeHandlerBuffers(handler, ctx); freeHandlerBuffers(handler, ctx);
} }
ctx.removed = true;
} }
private void freeHandlerBuffers(ChannelHandler handler, ChannelHandlerContext ctx) { private void freeHandlerBuffers(ChannelHandler handler, ChannelHandlerContext ctx) {