[3.0] fix #9962, recreate RpcInvocation in BroadcastClusterInvoker (#10027)

This commit is contained in:
Wang Chengming 2022-06-13 11:16:47 +08:00 committed by GitHub
parent d9d87bdab0
commit 6d188d81df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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) {

View File

@ -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();