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 extends AbstractClusterInvoker { int failIndex = 0; for (Invoker 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();