Adjusted frame length exceeds 4096: 5637-discarded server solution

Solve the server-side Adjusted frame length exceeds 4096: 5637-discarded problem
1. Specific error
2. Error reason
2.1 Length format problem
2.2 Length size problem
3. Solution
1. Specific error
The following shows some error details.

io.netty.handler.codec.TooLongFrameException: Adjusted frame length exceeds 4096: 18247-discarded
at io.netty.handler.codec.LengthFieldBasedFrameDecoder.fail(LengthFieldBasedFrameDecoder.java:503)
at io.netty.handler.codec.LengthFieldIfNecessary (LengthFieldBasedFrameDecoder.java:489)
AT io.netty.handler.codec.LengthFieldBasedFrameDecoder.exceededFrameLength (LengthFieldBasedFrameDecoder.java:376)
AT io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode (LengthFieldBasedFrameDecoder.java:419)
AT io.netty. handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:332)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:498)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:437)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext .java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext. channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel .java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
at io.netty.channel. nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989 )
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread. java:748)

2. Error reason
2.1 Length format problem
Netty’s own LengthFieldBasedFrameDecodr length coding protocol, the length offset value must be expressed in hexadecimal.

new LengthFieldBasedFrameDecoder(4*1024,0,2);
// Length bit: 000C means 12 length
// eg: 000C321453215435413415206753 (byte[] to hexadecimal representation)

2.2 Length size problem The
adjusted frame length exceeds 4096:18247- Has been discarded. I used the LengthFieldBasedFrameDecodr length protocol decoder when processing data packets on the netty server. Part of the code is as follows:

@Override
public void initChannel(SocketChannel ch) {
//Decoder of length protocol
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(4*1024,0,2));
ch.pipeline().addLast(new SocketServerHandler() );//Control category
}

And the length agreement sets a maximum acceptable length of 4*1024 = 4096. Therefore, after the server receives more than 4096 bytes, the server discards it as a junk packet.

3. Solution
Change the maximum acceptable length of the decoder of the length protocol of the netty server to be long enough according to the needs.

new LengthFieldBasedFrameDecoder(20*1024,0,2);

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *