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 2021/03/04 07:28:25 UTC
[dubbo] branch 3.0 updated: fix attachments override (#7311)
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 f6a24f7 fix attachments override (#7311)
f6a24f7 is described below
commit f6a24f770ae9be1d89a6fafcc2f096df77d33138
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Mar 4 15:28:05 2021 +0800
fix attachments override (#7311)
---
.../dubbo/rpc/cluster/support/AbstractClusterInvoker.java | 2 +-
.../org/apache/dubbo/rpc/filter/ConsumerContextFilter.java | 14 ++++++++++++++
.../org/apache/dubbo/rpc/protocol/AbstractInvoker.java | 11 -----------
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java
index 381d894..0974fcc 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java
@@ -258,7 +258,7 @@ public abstract class AbstractClusterInvoker<T> implements ClusterInvoker<T> {
// binding attachments into invocation.
Map<String, Object> contextAttachments = RpcContext.getContext().getObjectAttachments();
if (contextAttachments != null && contextAttachments.size() != 0) {
- ((RpcInvocation) invocation).addObjectAttachments(contextAttachments);
+ ((RpcInvocation) invocation).addObjectAttachmentsIfAbsent(contextAttachments);
}
List<Invoker<T>> invokers = list(invocation);
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java
index ad14831..0fead6b 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.filter;
import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.AsyncRpcResult;
import org.apache.dubbo.rpc.Filter;
@@ -28,6 +29,8 @@ import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.TimeoutCountDown;
+import java.util.Map;
+
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
@@ -52,6 +55,17 @@ public class ConsumerContextFilter implements Filter {
((RpcInvocation) invocation).setInvoker(invoker);
}
+ Map<String, Object> contextAttachments = RpcContext.getContext().getObjectAttachments();
+ if (CollectionUtils.isNotEmptyMap(contextAttachments)) {
+ /**
+ * invocation.addAttachmentsIfAbsent(context){@link RpcInvocation#addAttachmentsIfAbsent(Map)}should not be used here,
+ * because the {@link RpcContext#setAttachment(String, String)} is passed in the Filter when the call is triggered
+ * by the built-in retry mechanism of the Dubbo. The attachment to update RpcContext will no longer work, which is
+ * a mistake in most cases (for example, through Filter to RpcContext output traceId and spanId and other information).
+ */
+ ((RpcInvocation) invocation).addObjectAttachments(contextAttachments);
+ }
+
// pass default timeout set by end user (ReferenceConfig)
Object countDown = context.get(TIME_COUNTDOWN_KEY);
if (countDown != null) {
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
index 737a4ad..1b1b0af 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
@@ -145,17 +145,6 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
invocation.addObjectAttachmentsIfAbsent(attachment);
}
- Map<String, Object> contextAttachments = RpcContext.getContext().getObjectAttachments();
- if (CollectionUtils.isNotEmptyMap(contextAttachments)) {
- /**
- * invocation.addAttachmentsIfAbsent(context){@link RpcInvocation#addAttachmentsIfAbsent(Map)}should not be used here,
- * because the {@link RpcContext#setAttachment(String, String)} is passed in the Filter when the call is triggered
- * by the built-in retry mechanism of the Dubbo. The attachment to update RpcContext will no longer work, which is
- * a mistake in most cases (for example, through Filter to RpcContext output traceId and spanId and other information).
- */
- invocation.addObjectAttachments(contextAttachments);
- }
-
invocation.setInvokeMode(RpcUtils.getInvokeMode(url, invocation));
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);