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 80d7b9f0d56..abc9cf21afb 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 @@ -234,12 +234,6 @@ public Result invoke(final Invocation invocation) throws RpcException { Map contextAttachments = RpcContext.getContext().getAttachments(); if (contextAttachments != null && contextAttachments.size() != 0) { ((RpcInvocation) invocation).addAttachments(contextAttachments); - // We need to remove the interface because the interface here may come from last invoke. - // - // See https://github.com/apache/incubator-dubbo/issues/2981 - if (invocation.getAttachments() != null) { - invocation.getAttachments().remove(Constants.INTERFACE_KEY); - } } List> invokers = list(invocation); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index db68ea1a7f3..7f30151d1d1 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -42,8 +42,9 @@ public class ContextFilter implements Filter { public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { Map attachments = invocation.getAttachments(); if (attachments != null) { - attachments = new HashMap(attachments); + attachments = new HashMap<>(attachments); attachments.remove(Constants.PATH_KEY); + attachments.remove(Constants.INTERFACE_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); 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 89fb4678d31..d59af2b4502 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 @@ -134,7 +134,9 @@ public Result invoke(Invocation inv) throws RpcException { } RpcInvocation invocation = (RpcInvocation) inv; invocation.setInvoker(this); - + if (attachment != null && attachment.size() > 0) { + invocation.addAttachmentsIfAbsent(attachment); + } Map contextAttachments = RpcContext.getContext().getAttachments(); if (contextAttachments != null && contextAttachments.size() != 0) { /** @@ -150,15 +152,6 @@ public Result invoke(Invocation inv) throws RpcException { } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); - // If we have attachment, override the attachment to ensure that the last invoke's attach does not affect this call. - // In most cases, attachments contains interface, timeout, group, and token. - // These info should be override in each invoke. - // - // See https://github.com/apache/incubator-dubbo/issues/2981 - if (attachment != null && attachment.size() > 0) { - invocation.addAttachments(attachment); - } - try { return doInvoke(invocation); } catch (InvocationTargetException e) { // biz exception