Skip to content

fix(nacos): skip loopback addresses for network interface (2025.0.x backport of #4350) - #4388

Merged
uuuyuqi merged 1 commit into
alibaba:2025.0.xfrom
uuuyuqi:backport-4350-2025.0.x
Aug 27, 2026
Merged

uuuyuqi merged 1 commit into
alibaba:2025.0.xfrom
uuuyuqi:backport-4350-2025.0.x

Conversation

@uuuyuqi

@uuuyuqi uuuyuqi commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Describe what this PR does / why we need it

This PR backports #4350 to 2025.0.x.

When spring.cloud.nacos.discovery.network-interface is configured, the current condition is evaluated as IPv4 || (IPv6 && !loopback). As a result, an IPv4 loopback address such as 127.0.0.1 can be selected before a usable address on the same interface.

Does this pull request fix one issue?

Fixes #4362

Describe how you did it

  • Group the IPv4 and IPv6 type checks so that the loopback check applies to both address families.
  • Add a regression test with 127.0.0.1 before 192.168.1.10 and verify that the usable address is selected.
  • Align the same condition in two network-interface test helpers.

Describe how to verify it

  1. Focused regression test:

    ./mvnw -pl spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery -am -Dtest=NacosDiscoveryPropertiesTests#initShouldSkipLoopbackAddressFromNetworkInterface -Dsurefire.failIfNoSpecifiedTests=false test

    Result: 1 test passed, 0 failures, 0 errors.

  2. Directly affected test classes:

    ./mvnw -pl spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery -am -Dtest=NacosDiscoveryPropertiesTests,NacosAutoServiceRegistrationIpNetworkInterfaceTests -Dsurefire.failIfNoSpecifiedTests=false test

    Result: 8 tests passed, 0 failures, 0 errors.

  3. Full Nacos Discovery module:

    ./mvnw -pl spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery -am test

    Result: 62 tests passed, 0 failures, 0 errors. Checkstyle reported 0 violations.

Special notes for reviews

This PR replaces #4363, which has remained in draft and is blocked by a pending CLA. The patch is equivalent and is based on the latest 2025.0.x commit 9b3477ea4, including #4386 and #4387. A new 2025.0.x release is being prepared, so further updates can continue in this PR.

Ensure both IPv4 and IPv6 candidates are checked for loopback addresses
when a network interface is configured. Add regression coverage for
selecting a non-loopback address.

Backport of alibaba#4350 to 2025.0.x.

Fixes alibabagh-4362

@xuxiaowei-com-cn xuxiaowei-com-cn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@uuuyuqi
uuuyuqi merged commit e78a285 into alibaba:2025.0.x Aug 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants