[Backport][Nacos] Skip loopback addresses for network-interface on 2025.0.x
#4,362 opened on Jul 16, 2026
Repository metrics
- Stars
- (29,106 stars)
- PR merge metrics
- (Avg merge 6d 3h) (7 merged PRs in 30d)
Description
Which Component
Nacos Discovery (spring-cloud-starter-alibaba-nacos-discovery)
Describe the bug
PR #4350 has been merged into 2025.1.x and fixes the network-interface address selection problem reported in #4342.
However, the latest 2025.0.x branch at the time of verification (b8403af4b2d94460e54dd53552d2e87c7f6265c0) still contains the same condition in NacosDiscoveryProperties.init():
if (currentAddress instanceof Inet4Address
|| currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress()) {
ip = currentAddress.getHostAddress();
break;
}
Because && has higher precedence than ||, Java parses this as:
currentAddress instanceof Inet4Address
|| (currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress())
Therefore, the loopback check applies only to IPv6 addresses. When spring.cloud.nacos.discovery.network-interface is configured, an IPv4 loopback address such as 127.0.0.1 may be selected as the service registration IP, making the service unreachable from other nodes.
This issue tracks the backport of #4350 to 2025.0.x.
Simplest demo
The regression test added in #4350 can be used as the minimal reproduction:
NacosDiscoveryPropertiesTests#initShouldSkipLoopbackAddressFromNetworkInterface
The test mocks one network interface that returns these addresses in order:
127.0.0.1
192.168.1.10
The correct behavior is to skip 127.0.0.1 and select 192.168.1.10.
To Reproduce
- Check out the latest
2025.0.xbranch. - Port the regression test from #4350 without changing the production code.
- Run:
./mvnw \
-pl spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery \
-am \
-Dtest=NacosDiscoveryPropertiesTests#initShouldSkipLoopbackAddressFromNetworkInterface \
-Dsurefire.failIfNoSpecifiedTests=false \
test
The test fails with:
expected: "192.168.1.10"
but was: "127.0.0.1"
Expected behavior
Loopback addresses should be excluded for both IPv4 and IPv6:
(currentAddress instanceof Inet4Address
|| currentAddress instanceof Inet6Address)
&& !currentAddress.isLoopbackAddress()
The reproduction above should select 192.168.1.10. If the configured interface has no usable non-loopback address, the existing error handling should remain unchanged.
Suggested implementation
Please use the merged PR #4350 as the reference:
- Backport the production fix to
2025.0.x. - Add the regression test.
- Align the related helper conditions in
NacosAutoServiceRegistrationIpNetworkInterfaceTests. - Open a separate PR targeting
2025.0.xand link this issue.
Local verification:
- Before the fix: the regression test fails because
127.0.0.1is selected. - After applying the same parentheses fix as #4350: the regression test passes.
Contributions are welcome. If you would like to work on this issue, please leave a comment first to avoid duplicated effort.
Screenshots
Not applicable. The regression test output demonstrates the problem.
Additional context
- Target branch:
2025.0.x - Verified commit:
b8403af4b2d94460e54dd53552d2e87c7f6265c0 - JDK: 17
- Spring Boot: 3.5.0
- Original issue: #4342
- Fix merged into
2025.1.x: #4350 - No existing
2025.0.xbackport issue or PR was found before creating this issue.