Skip to content

fix(utils): make find_node_ip return a usable address on loopback-only hosts - #301

Merged
tastelikefeet merged 1 commit into
modelscope:mainfrom
li-lizhe:fix/find-node-ip-loopback
Oct 11, 2026
Merged

tastelikefeet merged 1 commit into
modelscope:mainfrom
li-lizhe:fix/find-node-ip-loopback

Conversation

@li-lizhe

@li-lizhe li-lizhe commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

find_node_ip() returns main_ip or virtual_ip, which is None on a host where no interface other than the loopback one exposes an IPv4 address — for example a process started with docker run --network none.

return main_ip or virtual_ip

RayHelper assigns that value to MASTER_ADDR:

env_vars['MASTER_ADDR'] = ip

None is not a valid value there, so the failure surfaces inside Ray's env_vars validation with an error that does not point back to the address lookup.

This PR makes the final fallback 127.0.0.1, which matches the existing intent of falling back to a virtual interface, and leaves the preference order (non-virtual interface → virtual interface) unchanged.

Verification

Pure-Python behaviour, reproduced before/after by loading src/twinkle/utils/network.py from a file path (with a fake psutil) and calling the real find_node_ip():

########## BEFORE (upstream main) ##########
  only loopback (docker --network none)      -> find_node_ip()=None  MASTER_ADDR=None  -> Ray env_vars TypeError (not a str)
  loopback + docker0                         -> find_node_ip()='172.17.0.1'  MASTER_ADDR='172.17.0.1'
  normal host                                -> find_node_ip()='10.0.0.5'  MASTER_ADDR='10.0.0.5'
########## AFTER (patched) ##########
  only loopback (docker --network none)      -> find_node_ip()='127.0.0.1'  MASTER_ADDR='127.0.0.1'
  loopback + docker0                         -> find_node_ip()='172.17.0.1'  MASTER_ADDR='172.17.0.1'
  normal host                                -> find_node_ip()='10.0.0.5'  MASTER_ADDR='10.0.0.5'

The first two cases are unchanged; only the loopback-only case changes. A regression test covering all four cases is added in tests/utils/test_network.py.

Not tested

  • No Ray cluster was started, so the exact downstream exception inside Ray was not reproduced; only the None value handed to MASTER_ADDR is demonstrated.

Fixes #302

…y hosts

find_node_ip() returned None when no interface other than the loopback one
exposes an IPv4 address (for example a container started with
`docker run --network none`). RayHelper assigns the result to MASTER_ADDR, and a
None there is not a valid env var value, so the failure surfaced deep inside
Ray rather than pointing at the address lookup.

Return 127.0.0.1 in that case, matching the intent of falling back to a virtual
interface, and keep the previous preference order otherwise.

Signed-off-by: li-lizhe <147392333@qq.com>
@tastelikefeet
tastelikefeet merged commit 8b78f8e into modelscope:main Oct 11, 2026
2 of 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.

find_node_ip() returns None on loopback-only hosts, which is not a valid MASTER_ADDR

2 participants