From 36e0cf5490f9ea289a9d809694b0b2347106a515 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:00:16 +0800 Subject: [PATCH] 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 --- .../rpc/cluster/filter/support/ConsumerContextFilter.java | 6 +----- .../org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java | 2 ++ .../org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java index 674e4a61e40..8ee541e291a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java @@ -19,7 +19,6 @@ import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.extension.ExtensionLoader; 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; import org.apache.dubbo.rpc.Invocation; @@ -63,10 +62,7 @@ public ConsumerContextFilter(ApplicationModel applicationModel) { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - RpcContext.getServiceContext() - .setInvoker(invoker) - .setInvocation(invocation) - .setLocalAddress(NetUtils.getLocalHost(), 0); + RpcContext.getServiceContext().setInvoker(invoker).setInvocation(invocation); RpcContext context = RpcContext.getClientAttachment(); context.setAttachment(REMOTE_APPLICATION_KEY, invoker.getUrl().getApplication()); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 2b2463defed..8b6eabe3c8a 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -34,6 +34,7 @@ import org.apache.dubbo.rpc.InvokeMode; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.protocol.AbstractInvoker; @@ -98,6 +99,7 @@ protected Result doInvoke(final Invocation invocation) throws Throwable { } else { currentClient = exchangeClients.get(index.getAndIncrement() % exchangeClients.size()); } + RpcContext.getServiceContext().setLocalAddress(currentClient.getLocalAddress()); try { boolean isOneway = RpcUtils.isOneway(getUrl(), invocation); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java index 32789bb0d51..fd1c4136269 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java @@ -155,6 +155,7 @@ protected Result doInvoke(final Invocation invocation) { isSync(methodDescriptor, invocation) ? new ThreadlessExecutor() : streamExecutor; ClientCall call = new TripleClientCall( connectionClient, callbackExecutor, getUrl().getOrDefaultFrameworkModel(), writeQueue); + RpcContext.getServiceContext().setLocalAddress(connectionClient.getLocalAddress()); AsyncRpcResult result; try { switch (methodDescriptor.getRpcType()) {