From a4b5b644acd62a75344bd4c1069a86f136d81d0f Mon Sep 17 00:00:00 2001 From: mmaxjr Date: Sun, 30 Aug 2026 09:22:54 -0300 Subject: [PATCH] Avoid external IP lookup for inproc addresses --- distributed/comm/inproc.py | 6 +----- distributed/comm/tests/test_comms.py | 7 +++---- distributed/deploy/tests/test_local.py | 22 ++++++++++++++++++++++ distributed/tests/test_core.py | 4 ++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/distributed/comm/inproc.py b/distributed/comm/inproc.py index ec774056e0..8e766c8caa 100644 --- a/distributed/comm/inproc.py +++ b/distributed/comm/inproc.py @@ -15,7 +15,6 @@ from distributed.comm.core import BaseListener, Comm, CommClosedError, Connector from distributed.comm.registry import Backend, backends from distributed.protocol.serialize import _nested_deserialize -from distributed.utils import get_ip logger = logging.getLogger(__name__) @@ -38,10 +37,7 @@ def __init__(self): @property def ip(self): if not self._ip: - try: - self._ip = get_ip() - except OSError: - self._ip = "127.0.0.1" + self._ip = "127.0.0.1" return self._ip def add_listener(self, addr, listener): diff --git a/distributed/comm/tests/test_comms.py b/distributed/comm/tests/test_comms.py index 306e875ece..41e42b3245 100644 --- a/distributed/comm/tests/test_comms.py +++ b/distributed/comm/tests/test_comms.py @@ -170,7 +170,7 @@ def test_get_address_host(tcp): f = get_address_host assert f("tcp://127.0.0.1:123") == "127.0.0.1" - assert f("inproc://%s/%d/123" % (get_ip(), os.getpid())) == get_ip() + assert f("inproc://127.0.0.1/%d/123" % os.getpid()) == "127.0.0.1" def test_resolve_address(tcp): @@ -201,7 +201,7 @@ def test_get_local_address_for(tcp): if has_ipv6(): assert f("tcp://[::1]:123") == "tcp://[::1]" - inproc_arg = "inproc://%s/%d/444" % (get_ip(), os.getpid()) + inproc_arg = "inproc://127.0.0.1/%d/444" % os.getpid() inproc_res = f(inproc_arg) assert inproc_res.startswith("inproc://") assert inproc_res != inproc_arg @@ -586,12 +586,11 @@ def checker(loc): def inproc_check(): - expected_ip = get_ip() expected_pid = os.getpid() def checker(loc): ip, pid, suffix = loc.split("/") - assert ip == expected_ip + assert ip == "127.0.0.1" assert int(pid) == expected_pid return checker diff --git a/distributed/deploy/tests/test_local.py b/distributed/deploy/tests/test_local.py index 443b8fc3bc..0e55f2cede 100644 --- a/distributed/deploy/tests/test_local.py +++ b/distributed/deploy/tests/test_local.py @@ -151,6 +151,28 @@ def test_transports_inproc(loop): assert e.submit(inc, 4).result() == 5 +def test_transports_inproc_does_not_discover_external_ip(loop): + import distributed.comm.inproc + + distributed.comm.inproc.global_manager._ip = None + with ( + mock.patch( + "distributed.comm.inproc.get_ip", + side_effect=AssertionError("inproc should not discover an external IP"), + create=True, + ), + LocalCluster( + n_workers=1, + processes=False, + silence_logs=False, + dashboard_address=":0", + loop=loop, + ) as c, + ): + assert c.scheduler_address.startswith("inproc://127.0.0.1/") + assert c.workers[0].address.startswith("inproc://127.0.0.1/") + + def test_transports_tcp(loop): # Have nannies => need TCP with LocalCluster( diff --git a/distributed/tests/test_core.py b/distributed/tests/test_core.py index 32d39b5f47..b522b87182 100644 --- a/distributed/tests/test_core.py +++ b/distributed/tests/test_core.py @@ -281,12 +281,12 @@ async def listen_on(cls, *args, **kwargs): async with listen_on(Server, "inproc://") as server: inproc_addr1 = server.address - assert inproc_addr1.startswith("inproc://%s/%d/" % (get_ip(), os.getpid())) + assert inproc_addr1.startswith("inproc://127.0.0.1/%d/" % os.getpid()) await assert_can_connect(inproc_addr1) async with listen_on(Server, "inproc://") as server2: inproc_addr2 = server2.address - assert inproc_addr2.startswith("inproc://%s/%d/" % (get_ip(), os.getpid())) + assert inproc_addr2.startswith("inproc://127.0.0.1/%d/" % os.getpid()) await assert_can_connect(inproc_addr2) await assert_can_connect(inproc_addr1)