matanox
matanox

Reputation: 13696

Netty pipeline warning

Netty 4 issues a warning "Discarded 1 inbound message(s) that reached at the end of the pipeline. Please check your pipeline configuration". What does it mean? how should it be handled? (previously reproduced here until solved per the accepted answer, but I'd rather have the general explanation about what does it mean and how the pipeline works)

Trying to max out netty feedback, the client-side pipeline is set as follows:

pipeline.addLast("logger", new LoggingHandler(LogLevel.TRACE))
pipeline.addLast("HttpRequestEncoder", new HttpClientCodec)
pipeline.addLast("handler", new myHandler)

All I'm getting logged on the client-side by Netty while two http messages are sent by it and successfully received and acknowledged by the server side is:

12 [main] DEBUG io.netty.util.internal.InternalLoggerFactory  - Using Log4J as the default logging framework
164 [nioEventLoopGroup-1-2] DEBUG io.netty.channel.nio.SelectorUtil  - Using select timeout of 500
164 [nioEventLoopGroup-1-2] DEBUG io.netty.channel.nio.SelectorUtil  - Epoll-bug workaround enabled = false
229 [nioEventLoopGroup-1-2] WARN io.netty.channel.DefaultChannelPipeline  - Discarded 1 inbound message(s) that reached at the end of the pipeline. Please check your pipeline configuration.
230 [nioEventLoopGroup-1-2] WARN io.netty.channel.DefaultChannelPipeline  - Discarded 1 inbound message(s) that reached at the end of the pipeline. Please check your pipeline configuration.

Whereas logging is set up minimally as so:

BasicConfigurator.configure       
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory)

Upvotes: 2

Views: 10502

Answers (4)

南山竹
南山竹

Reputation: 524

@eskatos is right, the pipeline's handler processing based on type matching, for example, SimpleChannelInboundHandler<HttpContent> will just process HttpContent, if you had not processed HttpReponse yet(add SimpleChannelInboundHandler<HttpReponse> into you pipeline), Netty will warning: Content-Length: <length> that reached at the tail of the pipeline. Please check your pipeline configuration.

So, the solution is to add corresponding ChannelInboundHandler/ChannelOutboundHandler into your pipeline.

But you need to know what's typed Handler missing first: find the DefaultChannelPipeline's channelRead method and debug into it to get msg.content().toString() that includes what the message missing.

One more thing, @Norman Maurer mentioned to enable debug logging is not working, because channelRead method does not log what's inside of the msg's content.

The channelRead method of DefaultChannelPipeline below here (Netty 4.1):

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            logger.debug(
                    "Discarded inbound message {} that reached at the tail of the pipeline. " +
                            "Please check your pipeline configuration.", msg);
        } finally {
            ReferenceCountUtil.release(msg);
        }
    }

Upvotes: 2

user3783271
user3783271

Reputation: 51

Netty 4 automatically add one last handler on your created pipeline, if event reaches this last handler it will through the message. Your last inbound handler should not fire the context event.

Remove this: ctx.fireChannelRead(msg);

Upvotes: 5

eskatos
eskatos

Reputation: 4434

In Netty 4, HTTP decoders, used in servers or clients, always generates multiple message objects per a single HTTP message:

1       * HttpRequest / HttpResponse
0 - n   * HttpContent
1       * LastHttpContent

In other words:

  • a server receive 1 HttpRequest, 0-n HttpContent(s) and 1 HttpLastContent
  • a client receive 1 HttpResponse, 0-n HttpContent(s) and 1 HttpLastContent.

So if your handler only consume HttpRequest/HttpResponse the other messages will reach the end of the pipeline. You need to consume them, this is where your pipeline is "misconfigured".

OTOH you can add a HttpObjectAggregator to your pipeline so that FullHttpRequest/FullHttpResponse messages are generated instead:

pipeline.addLast( "http-aggregator", new HttpObjectAggregator( MAX_SIZE ) );

But it means that the whole request or response, including the body entity, is loaded before your handler is invoked. Maybe you don't want that, YMMV.

Upvotes: 5

Norman Maurer
Norman Maurer

Reputation: 23557

This means that a message reached the end of the pipeline and no "inbound handler" was able to handle it. This most of the times shows a "configuration" error in the ChannelPipeline.

Upvotes: 1

Related Questions