angus-guo opened a new pull request, #8202:
URL: https://github.com/apache/incubator-seata/pull/8202
## Issue
`getIgnoredInterfacesLocalAddress(String[], String...)` returns the global
`LOCAL_ADDRESS` immediately when it has already been initialized, regardless of
the supplied `ignoredInterfaces` or `preferredNetworks` patterns. Once an
unfiltered lookup (through `getLocalAddress()` or `getLocalIp()`) has populated
the cache, a subsequent filtered lookup is answered from that cache without
evaluating its patterns.
**Symptom:** After `Server.start()` made registry settings reachable from
`application.yml` in #8187, the filters configured in YAML are read
successfully but then silently ignored here.
This was discovered in #8169:
```java
@Test
public void testIgnoredInterfacesAreAppliedAfterDefaultAddressIsCached() {
assertThat(NetUtil.getLocalAddress()).isNotNull();
assertThat(NetUtil.getIgnoredInterfacesLocalAddress(new String[]
{".*"})).isNull();
}
```
```text
expected: null
but was: /192.168.124.25
```
## Change
Keep caching only for semantically unfiltered lookups. A call with non-empty
`ignoredInterfaces` or `preferredNetworks` resolves through
`getLocalAddress0(...)` without reading or overwriting the default cache:
```java
if (CollectionUtils.isEmpty(ignoredInterfaces) &&
CollectionUtils.isEmpty(preferredNetworks)) {
if (LOCAL_ADDRESS != null) {
return LOCAL_ADDRESS;
}
InetAddress localAddress = getLocalAddress0(ignoredInterfaces,
preferredNetworks);
LOCAL_ADDRESS = localAddress;
return localAddress;
}
return getLocalAddress0(ignoredInterfaces, preferredNetworks);
```
`getLocalAddress()` and `getLocalIp()` (no arguments → both `null`) remain
cached. `Server.start()` performs its filtered lookup once at startup, so no
hot path loses caching.
The global cache predates the ignored-interface support added in #8090, and
the early return was never conditioned on whether the supplied parameters
matched the cached call's parameters.
## Tests
Three new cases in `NetUtilTest`:
- **`testIgnoredInterfacesAreAppliedAfterDefaultAddressIsCached`** — the
pattern `.*` matches every interface, so the result is `null` rather than the
cached address. **Fails before this change.**
- **`testPreferredNetworksAreAppliedAfterDefaultAddressIsCached`** — the
same early return bypassed `preferredNetworks`. Ignoring every interface
through the preferred-network path also yields no candidate, so the result is
`null`. **Fails before this change.**
- **`testUnfilteredLookupRemainsCached`** — the unfiltered lookup keeps
returning the same cached instance (no regression).
Both failing tests demonstrate the bug from #8169 and confirm the fix.
Existing tests in the same file only assert non-null results and do not verify
that the supplied rules affect selection, which is why the bug was not caught
earlier.
Verified:
- All 33 tests in `NetUtilTest` pass.
- All 693 tests in the `common` module pass.
- `spotless:check` and `checkstyle:check` pass on the `common` module.
## Checklist
- [x] **Check Ahead**
- [x] I have searched the
[issues](https://github.com/apache/incubator-seata/issues) of this repository
and believe that this is not a duplicate.
- [x] I am willing to try to fix this bug myself.
- [ ] I have added the change log of the current PR to
[changes/en-us/2.x.md](https://github.com/apache/incubator-seata/blob/2.x/changes/en-us/2.x.md)
and
[changes/zh-cn/2.x.md](https://github.com/apache/incubator-seata/blob/2.x/changes/zh-cn/2.x.md).
*(Will add once the PR number is assigned.)*
- [x] I have passed all the tests locally.
- [x] I have added the unit test for my change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]