From 3f72add89a41b3d94309bccb0d253515c0543b65 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 23 Jan 2013 07:27:00 +0100 Subject: [PATCH] [#976] Fix exception which will be raised by ChannelInboundHandler.discardInboundReadBytes() and ChannelOutboundHandler.discardOutboundReadBytes() if the handler remove it self from the pipeline --- .../java/io/netty/channel/DefaultChannelHandlerContext.java | 5 +++-- .../main/java/io/netty/channel/DefaultChannelPipeline.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index 39fcfc3dbc..38a68032b5 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -80,6 +80,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements private Runnable invokeFreeInboundBuffer0Task; private Runnable invokeFreeOutboundBuffer0Task; private Runnable invokeRead0Task; + boolean removed; DefaultChannelHandlerContext( DefaultChannelPipeline pipeline, EventExecutorGroup group, @@ -1084,7 +1085,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } catch (Throwable t) { pipeline.notifyHandlerException(t); } finally { - if (handler instanceof ChannelInboundByteHandler && !isInboundBufferFreed()) { + if (!removed && handler instanceof ChannelInboundByteHandler && !isInboundBufferFreed()) { try { ((ChannelInboundByteHandler) handler).discardInboundReadBytes(this); } catch (Throwable t) { @@ -1424,7 +1425,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } catch (Throwable t) { pipeline.notifyHandlerException(t); } finally { - if (handler instanceof ChannelOutboundByteHandler && !isOutboundBufferFreed()) { + if (!removed && handler instanceof ChannelOutboundByteHandler && !isOutboundBufferFreed()) { try { ((ChannelOutboundByteHandler) handler).discardOutboundReadBytes(this); } catch (Throwable t) { diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java index fee544b217..eb27e88399 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java @@ -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(); // Notify the complete removal. @@ -622,6 +622,7 @@ final class DefaultChannelPipeline implements ChannelPipeline { } else { freeHandlerBuffers(handler, ctx); } + ctx.removed = true; } private void freeHandlerBuffers(ChannelHandler handler, ChannelHandlerContext ctx) {