Look at a case of Netty error

Source: Internet
Author: User

Original address: http://stackoverflow.com/questions/16879104/ Netty-4-0-0-cr3-lengthfieldbasedframedecoder-maxframelength-exceeds-integer-ma?rq=1

The exact words of the questioner:


So far I had been amp ' d about upgrading from Netty version 3.5.7.Final to 4.0.0CR3 until I ran into my Final problem du Ring the upgrade ... the Lengthfieldbasedframedecoder. Each available constructor requires a maxframelength which I set to Integer.max_value if running the client/server I Get several stack traces (one shown below) that state, the Integer.max_value has been exceeded (2147483647). I have tried to take a shot at configuring the maximum channel buffer size by digging through the Channelconfig class in T He API Docs and various other StackOverflow post, still to no prevail. Does anyone know if there is a missing option I can set or a by-prevent the reads from even being this high?

Stack Trace:

io.netty.handler.codec.TooLongFrameException:Adjusted frame length exceeds 2147483647:4156555235-discardedat Io.netty.handler.codec.LengthFieldBasedFrameDecoder.fail (lengthfieldbasedframedecoder.java:486) at Io.netty.handler.codec.LengthFieldBasedFrameDecoder.failIfNecessary (lengthfieldbasedframedecoder.java:462) at Io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode (lengthfieldbasedframedecoder.java:397) at Io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode (lengthfieldbasedframedecoder.java:352) at Io.netty.handler.codec.ByteToMessageDecoder.callDecode (bytetomessagedecoder.java:111) at Io.netty.handler.codec.ByteToMessageDecoder.inboundBufferUpdated (bytetomessagedecoder.java:69) at Io.netty.channel.ChannelInboundByteHandlerAdapter.inboundBufferUpdated (Channelinboundbytehandleradapter.java : +) at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated ( defaultchannelhandlercontext.java:1031) at Io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpDated0 (defaultchannelhandlercontext.java:998) at Io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated (defaultchannelhandlercontext.java:978) At io.netty.handler.timeout.IdleStateHandler.inboundBufferUpdated (idlestatehandler.java:257) at Io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated (Defaultchannelhandlercontext.java : 1057) at Io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0 ( defaultchannelhandlercontext.java:998) at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated (defaultchannelhandlercontext.java:978) at io.netty.channel.DefaultChannelPipeline.fireInboundBufferUpdated ( defaultchannelpipeline.java:828) at Io.netty.channel.nio.abstractniobytechannel$niobyteunsafe.read ( abstractniobytechannel.java:118) at Io.netty.channel.nio.NioEventLoop.processSelectedKey (nioeventloop.java:429) At Io.netty.channel.nio.NioEventLoop.processSelectedKeys (nioeventloop.java:392) at Io.netty.channel.nio.NioEventLoop.run (Nioeventloop.java:322) at Io.netty.util.concurrent.singlethreadeventexecutor$2.run (singlethreadeventexecutor.java:114) at Java.lang.Thread.run (thread.java:680)

My Client is configured as followed:

Peerclient.bootstrap = new Bootstrap ();p EerClient.bootstrap.group (New Nioeventloopgroup ())          . Channel ( Niosocketchannel.class)          . Option (Channeloption.allocator, Unpooledbytebufallocator.default)          . Option ( Channeloption.connect_timeout_millis, 120000)          . Option (Channeloption.so_keepalive, True)          . Option ( Channeloption.tcp_nodelay, True)          . Option (Channeloption.so_reuseaddr, True)          . Handler ( Peerinitializer.newinstance ());
My Server Configuration:
Result.serverbootstrap = new Serverbootstrap (); Result.serverBootstrap.group (new Nioeventloopgroup (), New Nioeventloopgroup ())      . Channel (Nioserversocketchannel.class)      . Handler (new Logginghandler (Loglevel.info))      . Childhandler (Peerinitializer.newinstance ())      . Childoption (Channeloption.allocator, Unpooledbytebufallocator.default);
The Initchannel method overridden with a custom class extending Channelinitializer
public class Peerinitializer extends channelinitializer<socketchannel> @Overrideprotected void Initchannel ( Socketchannel ch) throws Exception {    final channelpipeline pipeline = Ch.pipeline ();    Pipeline.addlast (            messageencoder,            handshakedecoder.newinstance (),            Connectionhandler,            Handshakehandler,            new Lengthfieldbasedframedecoder (Integer.max_value, 0, 4),            MessageHandler);}
-----------------------------------------------------------------------------

Let's start with the analysis of how this error came about.

Judging by the result of this exception, this is

Io.netty.handler.codec.LengthFieldBasedFrameDecoder.fail (Long) This method is thrown out. This method only occurs when the parsed data exceeds the value of the maximum frame length defined by the Lengthfieldbasedframedecoder, so the data value is already very large and the maximum frame length defined by the exception information is 214748364 (Integer.max_value) is so many bytes, and the number of bytes actually taken is 4,156,555,235 bytes ... This is obviously the Internet to receive the super,. This is an error at the decoding operation (Handshakedecoder or Netty): ... This cannot be said to be a bug. It can only be said that when the network high concurrent byte transmission netty may not be so good
214748364
4156555235

so the man below can only add a log to his init initchannel.

Finish:

Look at a case of Netty error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.