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

crazyhzm 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 c674d8d825 Fix broadcast context being cleared (#10619)
c674d8d825 is described below

commit c674d8d825d636ee7f4f5228663860707a15f135
Author: Albumen Kevin <[email protected]>
AuthorDate: Mon Sep 19 14:47:49 2022 +0800

    Fix broadcast context being cleared (#10619)
---
 .../rpc/cluster/support/BroadcastClusterInvoker.java  | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 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 2367476030..6d03e36f16 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
@@ -28,10 +28,10 @@ import org.apache.dubbo.rpc.RpcInvocation;
 import org.apache.dubbo.rpc.cluster.Directory;
 import org.apache.dubbo.rpc.cluster.LoadBalance;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 
-import static org.apache.dubbo.rpc.Constants.ASYNC_KEY;
-
 /**
  * BroadcastClusterInvoker
  */
@@ -67,10 +67,15 @@ public class BroadcastClusterInvoker<T> extends 
AbstractClusterInvoker<T> {
 
         int failThresholdIndex = invokers.size() * broadcastFailPercent / 
MAX_BROADCAST_FAIL_PERCENT;
         int failIndex = 0;
-        for (Invoker<T> invoker : invokers) {
+        for (int i = 0, invokersSize = invokers.size(); i < invokersSize; i++) 
{
+            Invoker<T> invoker = invokers.get(i);
+            RpcContext.RestoreContext restoreContext = new 
RpcContext.RestoreContext();
             try {
-                RpcInvocation subInvocation = new RpcInvocation(invocation, 
invoker);
-                subInvocation.setAttachment(ASYNC_KEY, "true");
+                RpcInvocation subInvocation = new 
RpcInvocation(invocation.getTargetServiceUniqueName(),
+                    invocation.getServiceModel(), invocation.getMethodName(), 
invocation.getServiceName(), invocation.getProtocolServiceKey(),
+                    invocation.getParameterTypes(), invocation.getArguments(), 
invocation.copyObjectAttachments(),
+                    invocation.getInvoker(), Collections.synchronizedMap(new 
HashMap<>(invocation.getAttributes())),
+                    invocation instanceof RpcInvocation ? ((RpcInvocation) 
invocation).getInvokeMode() : null);
                 result = invokeWithContext(invoker, subInvocation);
                 if (null != result && result.hasException()) {
                     Throwable resultException = result.getException();
@@ -90,6 +95,10 @@ public class BroadcastClusterInvoker<T> extends 
AbstractClusterInvoker<T> {
                 if (failIndex == failThresholdIndex) {
                     break;
                 }
+            } finally {
+                if (i != invokersSize - 1) {
+                    restoreContext.restore();
+                }
             }
         }
 

Reply via email to