This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 7ad0b84 Merge pull request #2325, AsyncRpcResult should store the
copy of the RpcContext.
7ad0b84 is described below
commit 7ad0b84f34fc3c4ea052025793692c3c3ad84337
Author: bneliao <[email protected]>
AuthorDate: Wed Sep 19 11:18:59 2018 +0800
Merge pull request #2325, AsyncRpcResult should store the copy of the
RpcContext.
Fixes #2323
---
.../java/org/apache/dubbo/rpc/AsyncRpcResult.java | 5 +++--
.../main/java/org/apache/dubbo/rpc/RpcContext.java | 25 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
index 0ae9867..e9ed915 100644
---
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
+++
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
@@ -79,8 +79,9 @@ public class AsyncRpcResult extends AbstractResult {
});
}
this.valueFuture = future;
- this.storedContext = RpcContext.getContext();
- this.storedServerContext = RpcContext.getServerContext();
+ // employ copy of context avoid the other call may modify the context
content
+ this.storedContext = RpcContext.getContext().copyOf();
+ this.storedServerContext = RpcContext.getServerContext().copyOf();
}
@Override
diff --git
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
index f448650..0432229 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
@@ -131,6 +131,31 @@ public class RpcContext {
LOCAL.set(oldContext);
}
+
+ public RpcContext copyOf() {
+ RpcContext copy = new RpcContext();
+ copy.attachments.putAll(this.attachments);
+ copy.values.putAll(this.values);
+ copy.future = this.future;
+ copy.urls = this.urls;
+ copy.url = this.url;
+ copy.methodName = this.methodName;
+ copy.parameterTypes = this.parameterTypes;
+ copy.arguments = this.arguments;
+ copy.localAddress = this.localAddress;
+ copy.remoteAddress = this.remoteAddress;
+ copy.invokers = this.invokers;
+ copy.invoker = this.invoker;
+ copy.invocation = this.invocation;
+
+ copy.request = this.request;
+ copy.response = this.response;
+ copy.asyncContext = this.asyncContext;
+
+ return copy;
+ }
+
+
/**
* remove context.
*