This is an automated email from the ASF dual-hosted git repository.
LegendPei pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new dbea1859ef bugfix: NetUtil filtered lookups bypass the cached default
address (#8191)
dbea1859ef is described below
commit dbea1859ef46da881310ccf2dd0b3a27dcca22c8
Author: Nikhil Ramashasthri <[email protected]>
AuthorDate: Sat Aug 15 11:39:13 2026 -0400
bugfix: NetUtil filtered lookups bypass the cached default address (#8191)
* bugfix: NetUtil filtered lookups bypass the cached default address
* docs: register #8191 in 2.x changelogs
* bugfix: keep blank filter patterns on the default cache path
---------
Co-authored-by: legendpei <[email protected]>
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
.../java/org/apache/seata/common/util/NetUtil.java | 20 +++++++++++
.../org/apache/seata/common/util/NetUtilTest.java | 41 ++++++++++++++++++++++
4 files changed, 63 insertions(+)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 17ee0bc3e4..f469799d64 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -27,6 +27,7 @@ Add changes here for all PR submitted to the 2.x branch.
### bugfix:
- [[#8138](https://github.com/apache/incubator-seata/pull/8138)] fix TCC fence
cleanup deleting in-progress/unexpired sibling branch records
+- [[#8191](https://github.com/apache/incubator-seata/pull/8191)] fix NetUtil
filtered lookups bypassing ignoredInterfaces and preferredNetworks once the
default address is cached
- [[#8145](https://github.com/apache/incubator-seata/pull/8145)] fix global
lock batch acquire false-failure on Dameng(DM)
- [[#8157](https://github.com/apache/incubator-seata/pull/8157)] fix Saga
auto-configuration being skipped on Spring Boot 4.x because of a hard
`DataSourceAutoConfiguration` class reference
- [[#8160](https://github.com/apache/incubator-seata/pull/8160)] fix
fastjson2 JSONB concurrent ref deserialization
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index b794203bd5..abb4e5b94f 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -27,6 +27,7 @@
### bugfix:
- [[#8138](https://github.com/apache/incubator-seata/pull/8138)] 修复 TCC fence
清理时误删同一全局事务中仍在进行(TRIED)或未过期的分支记录的问题
+- [[#8191](https://github.com/apache/incubator-seata/pull/8191)] 修复默认本地地址缓存后
NetUtil 参数化查询绕过 ignoredInterfaces 和 preferredNetworks 的问题
- [#8145](https://github.com/apache/incubator-seata/pull/8145)
修复达梦(DM)数据库下全局锁批量获取被误判为失败的问题
- [[#8157](https://github.com/apache/incubator-seata/pull/8157)] 修复 Spring
Boot 4.x 下由于硬编码 `DataSourceAutoConfiguration` 类引用导致 Saga 自动配置被跳过的问题
- [[#8160](https://github.com/apache/incubator-seata/pull/8160)] 修复 fastjson2
JSONB 并发反序列化问题
diff --git a/common/src/main/java/org/apache/seata/common/util/NetUtil.java
b/common/src/main/java/org/apache/seata/common/util/NetUtil.java
index b75a14e9a8..d898310ca4 100644
--- a/common/src/main/java/org/apache/seata/common/util/NetUtil.java
+++ b/common/src/main/java/org/apache/seata/common/util/NetUtil.java
@@ -265,6 +265,14 @@ public class NetUtil {
*/
public static InetAddress getIgnoredInterfacesLocalAddress(
String[] ignoredInterfaces, String... preferredNetworks) {
+ // The global cache only ever holds the unfiltered default address,
and it predates
+ // the interface filtering support (#8090). A parameterized lookup
must evaluate its
+ // own filters, so it neither reads nor overwrites the default cache
(#8169). Blank
+ // patterns (e.g. an empty config value split into [""]) apply no
filtering, so they
+ // still go through the cache.
+ if (hasNonBlankPattern(ignoredInterfaces) ||
hasNonBlankPattern(preferredNetworks)) {
+ return getLocalAddress0(ignoredInterfaces, preferredNetworks);
+ }
if (LOCAL_ADDRESS != null) {
return LOCAL_ADDRESS;
}
@@ -273,6 +281,18 @@ public class NetUtil {
return localAddress;
}
+ private static boolean hasNonBlankPattern(String[] patterns) {
+ if (patterns == null) {
+ return false;
+ }
+ for (String pattern : patterns) {
+ if (StringUtils.isNotBlank(pattern)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static InetAddress getLocalAddress0(String[] ignoredInterfaces,
String... preferredNetworks) {
InetAddress localAddress = null;
try {
diff --git a/common/src/test/java/org/apache/seata/common/util/NetUtilTest.java
b/common/src/test/java/org/apache/seata/common/util/NetUtilTest.java
index bcf8f047dd..586530de47 100644
--- a/common/src/test/java/org/apache/seata/common/util/NetUtilTest.java
+++ b/common/src/test/java/org/apache/seata/common/util/NetUtilTest.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import java.net.Inet4Address;
import java.net.Inet6Address;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
@@ -205,6 +206,46 @@ public class NetUtilTest {
assertThat(NetUtil.getLocalAddress()).isNotNull();
}
+ @Test
+ public void testIgnoredInterfacesAreAppliedAfterDefaultAddressIsCached() {
+ // populate the default cache first, then a lookup ignoring every
interface
+ // must still evaluate its filter instead of returning the cached
default (#8169)
+ assertThat(NetUtil.getLocalAddress()).isNotNull();
+ assertThat(NetUtil.getIgnoredInterfacesLocalAddress(new String[]
{".*"}))
+ .isNull();
+ }
+
+ @Test
+ public void testFilteredLookupDoesNotOverwriteDefaultCache() {
+ InetAddress defaultAddress = NetUtil.getLocalAddress();
+ assertThat(defaultAddress).isNotNull();
+
+ // a filtered lookup that matches nothing must not clear or replace
the default cache
+ NetUtil.getIgnoredInterfacesLocalAddress(new String[] {".*"});
+ assertThat(NetUtil.getLocalAddress()).isEqualTo(defaultAddress);
+ }
+
+ @Test
+ public void testBlankPatternsStillUseDefaultCache() {
+ // an empty config value split into [""] applies no filtering, so the
lookup
+ // behaves exactly like the unfiltered default lookup and shares its
cache
+ InetAddress defaultAddress = NetUtil.getLocalAddress();
+ assertThat(defaultAddress).isNotNull();
+ assertThat(NetUtil.getIgnoredInterfacesLocalAddress(new String[]
{""})).isEqualTo(defaultAddress);
+ assertThat(NetUtil.getIgnoredInterfacesLocalAddress(null,
"")).isEqualTo(defaultAddress);
+ }
+
+ @Test
+ public void
testPreferredNetworksLookupResolvesAfterDefaultAddressIsCached() {
+ InetAddress defaultAddress = NetUtil.getLocalAddress();
+ assertThat(defaultAddress).isNotNull();
+
+ // a preferred-network lookup runs the interface scan (falling back to
the first
+ // valid ip when nothing matches) and leaves the default cache
untouched
+ assertThat(NetUtil.getLocalAddress("240.0.0.")).isNotNull();
+ assertThat(NetUtil.getLocalAddress()).isEqualTo(defaultAddress);
+ }
+
@Test
public void testIsValidIp() {
String localIp = "127.0.0.1";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]