Skip to content

Commit 36e0cf5

Browse files
authored
fix(#13305): RpcContext local address info get null on custom filter (#13751)
* fix(#13305): RpcContext local address info get null on custom filter * fix ci build failed * fix ci build failed
1 parent d50adb7 commit 36e0cf5

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.apache.dubbo.common.extension.Activate;
2020
import org.apache.dubbo.common.extension.ExtensionLoader;
2121
import org.apache.dubbo.common.utils.CollectionUtils;
22-
import org.apache.dubbo.common.utils.NetUtils;
2322
import org.apache.dubbo.rpc.AsyncRpcResult;
2423
import org.apache.dubbo.rpc.Filter;
2524
import org.apache.dubbo.rpc.Invocation;
@@ -63,10 +62,7 @@ public ConsumerContextFilter(ApplicationModel applicationModel) {
6362

6463
@Override
6564
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
66-
RpcContext.getServiceContext()
67-
.setInvoker(invoker)
68-
.setInvocation(invocation)
69-
.setLocalAddress(NetUtils.getLocalHost(), 0);
65+
RpcContext.getServiceContext().setInvoker(invoker).setInvocation(invocation);
7066

7167
RpcContext context = RpcContext.getClientAttachment();
7268
context.setAttachment(REMOTE_APPLICATION_KEY, invoker.getUrl().getApplication());

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.dubbo.rpc.InvokeMode;
3535
import org.apache.dubbo.rpc.Invoker;
3636
import org.apache.dubbo.rpc.Result;
37+
import org.apache.dubbo.rpc.RpcContext;
3738
import org.apache.dubbo.rpc.RpcException;
3839
import org.apache.dubbo.rpc.RpcInvocation;
3940
import org.apache.dubbo.rpc.protocol.AbstractInvoker;
@@ -98,6 +99,7 @@ protected Result doInvoke(final Invocation invocation) throws Throwable {
9899
} else {
99100
currentClient = exchangeClients.get(index.getAndIncrement() % exchangeClients.size());
100101
}
102+
RpcContext.getServiceContext().setLocalAddress(currentClient.getLocalAddress());
101103
try {
102104
boolean isOneway = RpcUtils.isOneway(getUrl(), invocation);
103105

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected Result doInvoke(final Invocation invocation) {
155155
isSync(methodDescriptor, invocation) ? new ThreadlessExecutor() : streamExecutor;
156156
ClientCall call = new TripleClientCall(
157157
connectionClient, callbackExecutor, getUrl().getOrDefaultFrameworkModel(), writeQueue);
158+
RpcContext.getServiceContext().setLocalAddress(connectionClient.getLocalAddress());
158159
AsyncRpcResult result;
159160
try {
160161
switch (methodDescriptor.getRpcType()) {

0 commit comments

Comments
 (0)