You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/06/13 03:17:08 UTC

[dubbo] branch 3.0 updated: [3.0] fix #9962, recreate RpcInvocation in BroadcastClusterInvoker (#10027)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 6d188d81df [3.0] fix #9962, recreate RpcInvocation in BroadcastClusterInvoker (#10027)
6d188d81df is described below

commit 6d188d81dff49a2c0e4964ecb3dcd1ac114956d9
Author: Wang Chengming <63...@qq.com>
AuthorDate: Mon Jun 13 11:16:47 2022 +0800

    [3.0] fix #9962, recreate RpcInvocation in BroadcastClusterInvoker (#10027)
---
 .../apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java  | 7 ++++++-
 .../src/main/java/org/apache/dubbo/rpc/RpcInvocation.java          | 5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
index 93604aa3e4..2367476030 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/BroadcastClusterInvoker.java
@@ -24,11 +24,14 @@ import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Result;
 import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.RpcInvocation;
 import org.apache.dubbo.rpc.cluster.Directory;
 import org.apache.dubbo.rpc.cluster.LoadBalance;
 
 import java.util.List;
 
+import static org.apache.dubbo.rpc.Constants.ASYNC_KEY;
+
 /**
  * BroadcastClusterInvoker
  */
@@ -66,7 +69,9 @@ public class BroadcastClusterInvoker<T> extends AbstractClusterInvoker<T> {
         int failIndex = 0;
         for (Invoker<T> invoker : invokers) {
             try {
-                result = invokeWithContext(invoker, invocation);
+                RpcInvocation subInvocation = new RpcInvocation(invocation, invoker);
+                subInvocation.setAttachment(ASYNC_KEY, "true");
+                result = invokeWithContext(invoker, subInvocation);
                 if (null != result && result.hasException()) {
                     Throwable resultException = result.getException();
                     if (null != resultException) {
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
index a7698cecd8..9e4244254c 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
@@ -17,6 +17,7 @@
 package org.apache.dubbo.rpc;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.CollectionUtils;
 import org.apache.dubbo.common.utils.ReflectUtils;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.rpc.model.FrameworkModel;
@@ -112,7 +113,9 @@ public class RpcInvocation implements Invocation, Serializable {
     public RpcInvocation(Invocation invocation, Invoker<?> invoker) {
         this(invocation.getTargetServiceUniqueName(), invocation.getServiceModel(), invocation.getMethodName(), invocation.getServiceName(),
             invocation.getProtocolServiceKey(), invocation.getParameterTypes(), invocation.getArguments(),
-            Collections.synchronizedMap(invocation.getObjectAttachments()), invocation.getInvoker(), invocation.getAttributes(),
+            CollectionUtils.isEmptyMap(invocation.getObjectAttachments()) ?
+                Collections.synchronizedMap(new HashMap<>()) : Collections.synchronizedMap(invocation.getObjectAttachments()),
+            invocation.getInvoker(), invocation.getAttributes(),
             invocation instanceof RpcInvocation ? ((RpcInvocation) invocation).getInvokeMode() : null);
         if (invoker != null) {
             URL url = invoker.getUrl();