Skip to content

Commit 42fe1cf

Browse files
committed
Adapt worker and nanny to ipv6
1 parent 1ee4756 commit 42fe1cf

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

distributed/comm/tcp.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from distributed.protocol.utils import host_array, pack_frames_prelude, unpack_frames
4141
from distributed.system import MEMORY_LIMIT
42-
from distributed.utils import ensure_ip, ensure_memoryview, get_ip, get_ipv6, nbytes
42+
from distributed.utils import ensure_ip, ensure_memoryview, get_ip, nbytes
4343

4444
logger = logging.getLogger(__name__)
4545

@@ -759,10 +759,7 @@ def resolve_address(self, loc):
759759
def get_local_address_for(self, loc):
760760
host, port = parse_host_port(loc)
761761
host = ensure_ip(host)
762-
if ":" in host:
763-
local_host = get_ipv6(host)
764-
else:
765-
local_host = get_ip(host)
762+
local_host = get_ip(host)
766763
return unparse_host_port(local_host, None)
767764

768765

distributed/nanny.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from distributed import preloading
2828
from distributed._async_taskgroup import AsyncTaskGroupClosedError
2929
from distributed.comm import get_address_host
30-
from distributed.comm.addressing import address_from_user_args
30+
from distributed.comm.addressing import address_from_user_args, unparse_host_port
3131
from distributed.compatibility import asyncio_run
3232
from distributed.config import get_loop_factory
3333
from distributed.core import (
@@ -276,7 +276,7 @@ def __init__( # type: ignore[no-untyped-def]
276276
and not interface
277277
and not self.scheduler_addr.startswith("inproc://")
278278
):
279-
host = get_ip(get_address_host(self.scheduler.address))
279+
host = unparse_host_port(get_ip(get_address_host(self.scheduler.address)))
280280

281281
self._start_port = port
282282
self._start_host = host

distributed/node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def start_http_server(
176176
bound_addresses = get_tcp_server_addresses(self.http_server)
177177

178178
# If more than one address is configured we just use the first here
179-
self.http_server.address, self.http_server.port = bound_addresses[0]
179+
# Socket addresses representation: https://docs.python.org/3/library/socket.html#socket-families
180+
self.http_server.address, self.http_server.port = bound_addresses[0][:2]
180181
self.services["dashboard"] = self.http_server
181182

182183
# Warn on port changes

distributed/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,15 @@ def get_ip(host="8.8.8.8", port=80):
213213
"""
214214
Get the local IP address through which the *host* is reachable.
215215
216+
It will try to get ipv4 or ipv6 adaptively depending on the *host* to reach.
217+
216218
*host* defaults to a well-known Internet host (one of Google's public
217219
DNS servers).
218220
"""
219-
return _get_ip(host, port, family=socket.AF_INET)
221+
if ":" in host:
222+
return _get_ip(host, port, family=socket.AF_INET6)
223+
else:
224+
return _get_ip(host, port, family=socket.AF_INET)
220225

221226

222227
def get_ipv6(host="2001:4860:4860::8888", port=80):

0 commit comments

Comments
 (0)