chickenlj closed pull request #2325: [Dubbo-2323]the AsyncRpcResult should
store the copy of the context #2323
URL: https://github.com/apache/incubator-dubbo/pull/2325
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 0ae9867dd0..e9ed9156c0 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 AsyncRpcResult(CompletableFuture<Object> future, final
CompletableFuture<
});
}
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 f448650bc0..043222976a 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 static void restoreContext(RpcContext oldContext) {
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.
*
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]