Skip to content

Commit a4b5b64

Browse files
committed
Avoid external IP lookup for inproc addresses
1 parent dc182bd commit a4b5b64

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

distributed/comm/inproc.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from distributed.comm.core import BaseListener, Comm, CommClosedError, Connector
1616
from distributed.comm.registry import Backend, backends
1717
from distributed.protocol.serialize import _nested_deserialize
18-
from distributed.utils import get_ip
1918

2019
logger = logging.getLogger(__name__)
2120

@@ -38,10 +37,7 @@ def __init__(self):
3837
@property
3938
def ip(self):
4039
if not self._ip:
41-
try:
42-
self._ip = get_ip()
43-
except OSError:
44-
self._ip = "127.0.0.1"
40+
self._ip = "127.0.0.1"
4541
return self._ip
4642

4743
def add_listener(self, addr, listener):

distributed/comm/tests/test_comms.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_get_address_host(tcp):
170170
f = get_address_host
171171

172172
assert f("tcp://127.0.0.1:123") == "127.0.0.1"
173-
assert f("inproc://%s/%d/123" % (get_ip(), os.getpid())) == get_ip()
173+
assert f("inproc://127.0.0.1/%d/123" % os.getpid()) == "127.0.0.1"
174174

175175

176176
def test_resolve_address(tcp):
@@ -201,7 +201,7 @@ def test_get_local_address_for(tcp):
201201
if has_ipv6():
202202
assert f("tcp://[::1]:123") == "tcp://[::1]"
203203

204-
inproc_arg = "inproc://%s/%d/444" % (get_ip(), os.getpid())
204+
inproc_arg = "inproc://127.0.0.1/%d/444" % os.getpid()
205205
inproc_res = f(inproc_arg)
206206
assert inproc_res.startswith("inproc://")
207207
assert inproc_res != inproc_arg
@@ -586,12 +586,11 @@ def checker(loc):
586586

587587

588588
def inproc_check():
589-
expected_ip = get_ip()
590589
expected_pid = os.getpid()
591590

592591
def checker(loc):
593592
ip, pid, suffix = loc.split("/")
594-
assert ip == expected_ip
593+
assert ip == "127.0.0.1"
595594
assert int(pid) == expected_pid
596595

597596
return checker

distributed/deploy/tests/test_local.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ def test_transports_inproc(loop):
151151
assert e.submit(inc, 4).result() == 5
152152

153153

154+
def test_transports_inproc_does_not_discover_external_ip(loop):
155+
import distributed.comm.inproc
156+
157+
distributed.comm.inproc.global_manager._ip = None
158+
with (
159+
mock.patch(
160+
"distributed.comm.inproc.get_ip",
161+
side_effect=AssertionError("inproc should not discover an external IP"),
162+
create=True,
163+
),
164+
LocalCluster(
165+
n_workers=1,
166+
processes=False,
167+
silence_logs=False,
168+
dashboard_address=":0",
169+
loop=loop,
170+
) as c,
171+
):
172+
assert c.scheduler_address.startswith("inproc://127.0.0.1/")
173+
assert c.workers[0].address.startswith("inproc://127.0.0.1/")
174+
175+
154176
def test_transports_tcp(loop):
155177
# Have nannies => need TCP
156178
with LocalCluster(

distributed/tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ async def listen_on(cls, *args, **kwargs):
281281

282282
async with listen_on(Server, "inproc://") as server:
283283
inproc_addr1 = server.address
284-
assert inproc_addr1.startswith("inproc://%s/%d/" % (get_ip(), os.getpid()))
284+
assert inproc_addr1.startswith("inproc://127.0.0.1/%d/" % os.getpid())
285285
await assert_can_connect(inproc_addr1)
286286

287287
async with listen_on(Server, "inproc://") as server2:
288288
inproc_addr2 = server2.address
289-
assert inproc_addr2.startswith("inproc://%s/%d/" % (get_ip(), os.getpid()))
289+
assert inproc_addr2.startswith("inproc://127.0.0.1/%d/" % os.getpid())
290290
await assert_can_connect(inproc_addr2)
291291

292292
await assert_can_connect(inproc_addr1)

0 commit comments

Comments
 (0)