Fix a bug where freeInbound/OutboundBuffer() is not called when a handler is removed from a pipeline.

This commit is contained in:
Trustin Lee 2013-01-14 20:48:58 +09:00
parent 49bf02ce09
commit a03bc6ea1d

View File

@ -598,9 +598,27 @@ final class DefaultChannelPipeline implements ChannelPipeline {
}
}
private static void callAfterRemove(ChannelHandlerContext ctx) {
private void callAfterRemove(ChannelHandlerContext ctx) {
// Free all buffers before completing removal.
ChannelHandler handler = ctx.handler();
if (handler instanceof ChannelInboundHandler) {
try {
((ChannelInboundHandler) handler).freeInboundBuffer(ctx);
} catch (Exception e) {
notifyHandlerException(e);
}
}
if (handler instanceof ChannelOutboundHandler) {
try {
((ChannelOutboundHandler) handler).freeOutboundBuffer(ctx);
} catch (Exception e) {
notifyHandlerException(e);
}
}
// Notify the complete removal.
try {
ctx.handler().afterRemove(ctx);
handler.afterRemove(ctx);
} catch (Throwable t) {
throw new ChannelPipelineException(
ctx.handler().getClass().getName() +