开发者社区 > 云原生 > 正文

dubbo 3.2.0版本中序列化问题

JDK8 Dubbo:3.2.0 为什么以下两种情况都会解码失败 1.service.exec(new HashMap<String,Object>() {{ put("flag", 1); }}); // 失败

Map<String,Object> params.... params.put("flag",1); service.exec(params); //可以成功 2.service.deleteBy(new Long[]{1L});

补充一下,调整序列化为hessian2是没有问题的

public class Consumer { private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");

public static void main(String[] args) throws InterruptedException {
    ReferenceConfig<Provider.UserService> reference = new ReferenceConfig<>();

    ApplicationConfig application = new ApplicationConfig("dubbo-consumer");
    application.setQosEnable(false);
    reference.setApplication(application);

    reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    reference.setInterface(Provider.UserService.class);
    Provider.UserService service = reference.get();
    CountDownLatch countDownLatch = new CountDownLatch(64);
    long t1 = System.currentTimeMillis();
    for (int i = 0; i < 64; i++) {
        new Thread(() -> {
            for (int i1 = 0; i1 < 10000; i1++) {
                service.exec(new HashMap<String,Object>() {{
                    put("a", 1);
                }});
                service.deleteBy(new Long[]{1L});
            }
            countDownLatch.countDown();

        }).start();
    }
    countDownLatch.await();
    System.err.println("QPS:" + (64 * 10000 / (System.currentTimeMillis() - t1) * 1000));

}

}

org.apache.dubbo.rpc.RpcException: Failed to invoke the method deleteBy in the service com.example.dubbo.Provider$UserService. Tried 3 times of the providers [10.88.107.34:20880] (1/1) from the registry 127.0.0.1:2181 on the consumer 10.88.107.34 using the dubbo version 3.2.0. Last error is: Failed to invoke remote method: deleteBy, provider: dubbo://10.88.107.34:20880/com.example.dubbo.Provider$UserService?anyhost=true&application=dubbo-provider&background=false&category=providers,configurators,routers&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&executor-management-mode=isolation&file-cache=true&generic=false&interface=com.example.dubbo.Provider$UserService&methods=deleteBy,exec&pid=10516&prefer.serialization=fastjson2,hessian2&qos.enable=false&release=3.2.0&service-name-mapping=true&side=provider&sticky=false&unloadClusterRelated=false, cause: org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=deleteBy, parameterTypes=null] at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:115) at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:341) at org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter.invoke(RouterSnapshotFilter.java:46) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:101) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter.invoke(MetricsClusterFilter.java:51) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:52) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter.invoke(ObservationSenderFilter.java:61) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.spring.security.filter.ContextHolderParametersSelectedTransferFilter.invoke(ContextHolderParametersSelectedTransferFilter.java:41) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter.invoke(ConsumerClassLoaderFilter.java:40) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter.invoke(ConsumerContextFilter.java:118) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:194) at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$ClusterFilterInvoker.invoke(AbstractCluster.java:91) at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:103) at org.apache.dubbo.rpc.cluster.support.wrapper.ScopeClusterInvoker.invoke(ScopeClusterInvoker.java:131) at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:284) at org.apache.dubbo.rpc.proxy.InvocationUtil.invoke(InvocationUtil.java:57) at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:75) at com.example.dubbo.Provider$UserServiceDubboProxy0.deleteBy(Provider$UserServiceDubboProxy0.java) at com.example.dubbo.Consumer.lambda$main$0(Consumer.java:38) at java.base/java.lang.Thread.run(Thread.java:1623) Caused by: java.util.concurrent.ExecutionException: org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=deleteBy, parameterTypes=null] at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096) at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:208) at org.apache.dubbo.rpc.protocol.AbstractInvoker.waitForResultIfSync(AbstractInvoker.java:286) at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:189) at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:71) at org.apache.dubbo.metrics.filter.MetricsFilter.invoke(MetricsFilter.java:51) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:331) at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:194) at org.apache.dubbo.rpc.protocol.ReferenceCountInvokerWrapper.invoke(ReferenceCountInvokerWrapper.java:78) at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invokeWithContext(AbstractClusterInvoker.java:380) at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:81) ... 27 more Caused by: org.apache.dubbo.remoting.RemotingException: Fail to decode request due to: RpcInvocation [methodName=deleteBy, parameterTypes=null] at org.apache.dubbo.remoting.exchange.support.DefaultFuture.doReceived(DefaultFuture.java:219) at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:181) at org.apache.dubbo.remoting.exchange.support.DefaultFuture.received(DefaultFuture.java:169) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleResponse(HeaderExchangeHandler.java:63) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:192) at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:53) at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:62) at org.apache.dubbo.common.threadpool.ThreadlessExecutor$RunnableWrapper.run(ThreadlessExecutor.java:141) at org.apache.dubbo.common.threadpool.ThreadlessExecutor.waitAndDrain(ThreadlessExecutor.java:70) at org.apache.dubbo.rpc.AsyncRpcResult.get(AsyncRpcResult.java:202) ... 36 more

public class Provider { private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");

public static void main(String[] args) throws Exception {
    ServiceConfig<UserService> service = new ServiceConfig<>();

    ApplicationConfig application = new ApplicationConfig("dubbo-provider");
    application.setQosEnable(false);
    service.setApplication(application);

    service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    service.setInterface(UserService.class);
    service.setRef(new UserServiceImpl());
    service.export();

    System.out.println("Dubbo provider started");

    new CountDownLatch(1).await();
}


public static class UserServiceImpl implements UserService {

    @Override
    public String exec(Map<String, Object> params) {
        return "success";
    }

    @Override
    public void deleteBy(Long[] ids) {
        System.out.println(JSON.toJSONString(ids));

    }
}

interface UserService {
    /**
     * 按照条件执行
     *
     * @param params
     * @return
     */
    String exec(Map<String, Object> params);

    /**
     * 删除
     *
     * @param ids
     */
    void deleteBy(Long[] ids);
}

}

[traceId: ] 2023-05-04 09:22:31 [NettyServerWorker-3-1] WARN org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation - [DUBBO] Decode rpc invocation failed: array not support input TYPED_ANY -110 [1], offset 1/10, dubbo version: 3.2.0, current host: 10.88.107.34, error code: 4-20. This may be caused by , go to https://dubbo.apache.org/faq/4/20 to find instructions. com.alibaba.fastjson2.JSONException: array not support input TYPED_ANY -110 [1], offset 1/10 at com.alibaba.fastjson2.JSONReaderJSONB.startArray(JSONReaderJSONB.java:1265) at com.alibaba.fastjson2.reader.ObjectReaderImplInt64Array.readJSONBObject(ObjectReaderImplInt64Array.java:92) at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:535) at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput.readObject(FastJson2ObjectInput.java:118) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.drawArgs(DecodeableRpcInvocation.java:261) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:162) at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:102) at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.decodeBody(DubboCodec.java:173) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:138) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.decode(ExchangeCodec.java:92) at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.decode(DubboCountCodec.java:60) at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalDecoder.decode(NettyCodecAdapter.java:103) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:1623)

原提问者GitHub用户C20171008S

展开
收起
大圣东游 2023-05-11 15:38:02 182 0
1 条回答
写回答
取消 提交回答
  • 问题已修复,请帮忙用2.0.30-SNAPSHOT版本验证,2.0.30版本预计在周末5月7日前发布。

    https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.30-SNAPSHOT/

    原回答者GitHub用户wenshao

    2023-05-12 10:40:20
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
Dubbo开源现状与2.7规划 立即下载
Dubbo分布式服务治理实战 立即下载
《Dubbo 3.0 前瞻》 立即下载