[apache/dubbo]Dubbo java17 大list 情况下 fastjson2 序列化异常

2023-12-11 167 views
1
  • Dubbo version: 3.2.5
  • Java version: 11,17
  • fastjson2 2.0.39 list 在 一万多条 list 直接用 JSON.toJSONString ,打印正常 在 java 8 环境下,正常 在 java 11,17 会出现异常

java.io.IOException: org.apache.dubbo.common.serialize.SerializationException: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 1594332 out of bounds for byte[1594323] at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper.handleToIOException(DefaultSerializationExceptionWrapper.java:358) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper.access$000(DefaultSerializationExceptionWrapper.java:28) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper$ProxyObjectOutput.writeObject(DefaultSerializationExceptionWrapper.java:324) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.encodeResponseData(DubboCodec.java:306) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeResponse(ExchangeCodec.java:325) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:81) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:51) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.transport.netty4.NettyChannel.send(NettyChannel.java:192) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.send(HeaderExchangeChannel.java:107) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.send(HeaderExchangeChannel.java:96) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.lambda$handleRequest$0(HeaderExchangeHandler.java:120) ~[dubbo-3.2.5.jar:3.2.5] at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na] at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:887) ~[na:na] at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2325) ~[na:na] at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:144) ~[na:na] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:111) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:200) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:53) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:62) ~[dubbo-3.2.5.jar:3.2.5] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na] at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41) ~[dubbo-3.2.5.jar:3.2.5] at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na] Caused by: org.apache.dubbo.common.serialize.SerializationException: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 1594332 out of bounds for byte[1594323] ... 23 common frames omitted Caused by: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 1594332 out of bounds for byte[1594323] at java.base/java.lang.System.arraycopy(Native Method) ~[na:na] at com.alibaba.fastjson2.JSONWriterJSONB.writeString(JSONWriterJSONB.java:695) ~[fastjson2-2.0.39.jar:na] at com.alibaba.fastjson2.writer.OWG_12_45_DriverDTO.writeJSONB(Unknown Source) ~[na:na] at com.alibaba.fastjson2.writer.ObjectWriterImplList.writeJSONB(ObjectWriterImplList.java:230) ~[fastjson2-2.0.39.jar:na] at com.alibaba.fastjson2.JSONB.toBytes(JSONB.java:1225) ~[fastjson2-2.0.39.jar:na] at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectOutput.writeObject(FastJson2ObjectOutput.java:106) ~[dubbo-3.2.5.jar:3.2.5] at org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper$ProxyObjectOutput.writeObject(DefaultSerializationExceptionWrapper.java:322) ~[dubbo-3.2.5.jar:3.2.5] ... 20 common frames omitted

回答

8

再次在java17 环境中测试 fastjson2 JSONB.toBytes , list 在2000左右就同样的异常了,java8 10000也没问,应该是 fastjson2 的bug

5

确认 fastjson2 bug,在即将发布的 fastjson2 2.0.40 中修复,希望 dubbo 下个版本 update version issues 1812

0

dubbo最新版本的fastjson2才 2.0.35,估计 2.0.40 还早

1

我倒是已经用上了,dubbo使用 fastjson2 后我就转过去了,然后也发现了蛮多 bug,现在这个 2.0.35 够用了

7

请不要用Fastjson2,真的很多bug

4

3.1 升级至 3.2

升级文档中提到了 Dubbo 3.2 的默认序列化方式由 hessian2 切换为 fastjson2,不过可以手动改回 hessian2 或 fastjson,在 Dubbo 暂未发布新版本前可以修改配置文件来解决问题。

dubbo.provider.prefer-serialization=fastjson,hessian2
dubbo.provider.serialization=hessian2