JsonObjectDecoder incorrect CorruptedFrameException?
See original GitHub issueI have come across some strange behaviour while using the JsonObjectDecoder class. It is very intermittent but I managed to reproduce and provide a unit test below to demonstrate the issue. It appears from some initial investigation that the problem lies with the use of different ByteBufs, but I’ll leave that for your analysis. Perhaps I’m not using the class correctly?
The 2 below JSON Strings are the minimal strings I could reproduce the issue with:
{
"a":{
"b":{
"c":{
"d":"27301",
"med":"d",
"path":"27310"
}
},
"status":"OK"
}
}
and the partial:
{
"a":{
"b":{
"c":{
"ory":[
{
"competi":[
{
"event":[
{
"externalI":{
"external":[
{
"id":"O"
}
]
Expected behavior
The JSON strings (one complete, one partial) are submitted to the JsonObjectDecoder split across 2 separate writes. I believe it should not throw a corrupt frame exception, it should produce one JSON string as output and remain read for further data, to arrive to complete the second JSON string, etc.
Actual behavior
The code throws a CorruptedFrameException as indicated by the stacktrace below:
io.netty.handler.codec.CorruptedFrameException: invalid JSON received at byte position 82: 5d
at io.netty.handler.codec.json.JsonObjectDecoder.decode(JsonObjectDecoder.java:163)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:274)
Steps to reproduce
Please use the Unit Test provided below.
Minimal yet complete reproducer code (or URL to code)
@Test
public void testCorruptedFrameException() {
final String part1 = "{\"a\":{\"b\":{\"c\":{ \"d\":\"27301\", \"med\":\"d\", \"path\":\"27310\"} }, \"status\":\"OK\" } }{\"";
final String part2 = "a\":{\"b\":{\"c\":{\"ory\":[{\"competi\":[{\"event\":[{" + "\"externalI\":{\"external\":[{\"id\":\"O\"} ]";
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
ch.writeInbound(Unpooled.copiedBuffer(part1, CharsetUtil.UTF_8));
ch.readInbound();
ch.writeInbound(Unpooled.copiedBuffer(part2, CharsetUtil.UTF_8));
ch.readInbound();
}
Netty version
4.1.6.Final
JVM version (e.g. java -version
)
java version “1.8.0_40” Java™ SE Runtime Environment (build 1.8.0_40-b27) Java HotSpot™ 64-Bit Server VM (build 25.40-b25, mixed mode)
OS version (e.g. uname -a
)
Darwin <hostname> 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
I think you’re right - I’ve added this test to my PR because this seems to fix it and is far simpler than the tests I was trying to write.
hello, I still facing the same issue with using latest version io.netty:4.1.82: io.netty.handler.codec.CorruptedFrameException: invalid JSON received at byte position 523: 00,.Could you help for this and how can I fix this problem?