From 5ded050f7bb0b046892623194291b1ab021a5510 Mon Sep 17 00:00:00 2001 From: Dmitriy Dumanskiy Date: Mon, 1 Jul 2019 21:38:59 +0300 Subject: [PATCH] #7285 Improved "Discarded inbound message" warning (#9286) Motivation: On servers with many pipelines or dynamic pipelines, it is easy for end user to make mistake during pipeline configuration. Current message: `Discarded inbound message PooledUnsafeDirectByteBuf(ridx: 0, widx: 2, cap: 2) that reached at the tail of the pipeline. Please check your pipeline configuration.` Is not always meaningful and doesn't allow to find the wrong pipeline quickly. Modification: Added additional log placeholder that identifies pipeline handlers and channel info. This will allow for the end users quickly find the problem pipeline. Result: Meaningful warning when the message reaches the end of the pipeline. Fixes #7285 --- .../io/netty/channel/DefaultChannelPipeline.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java index 9017f14e6c..f40c6ddc01 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java @@ -1198,6 +1198,19 @@ public class DefaultChannelPipeline implements ChannelPipeline { } } + /** + * Called once a message hit the end of the {@link ChannelPipeline} without been handled by the user + * in {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}. This method is responsible + * to call {@link ReferenceCountUtil#release(Object)} on the given msg at some point. + */ + protected void onUnhandledInboundMessage(ChannelHandlerContext ctx, Object msg) { + onUnhandledInboundMessage(msg); + if (logger.isDebugEnabled()) { + logger.debug("Discarded message pipeline : {}. Channel : {}.", + ctx.pipeline().names(), ctx.channel()); + } + } + /** * Called once the {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)} event hit * the end of the {@link ChannelPipeline}. @@ -1291,7 +1304,7 @@ public class DefaultChannelPipeline implements ChannelPipeline { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { - onUnhandledInboundMessage(msg); + onUnhandledInboundMessage(ctx, msg); } @Override