Skip to content

Commit 2a6ee53

Browse files
committed
Non-link-local IP4 > non-link-local IP6 > link-local IP4 > link-local IP6
1 parent c0e9eb4 commit 2a6ee53

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/cluster.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,12 +1279,25 @@ function terminate_all_workers()
12791279
end
12801280

12811281
function choose_bind_addr()
1282-
# On HPC clusters, link-local addresses are usually not usable for
1283-
# communication between compute nodes.
1284-
# Therefore, we use the first non-link-local IPv4 address.
1285-
addrs = Sockets.getipaddrs(Sockets.IPv4)
1286-
filter!(!Sockets.islinklocaladdr, addrs)
1287-
return first(addrs)
1282+
# We prefer IPv4 over IPv6.
1283+
#
1284+
# We also prefer non-link-local over link-local.
1285+
# (This is because on HPC clusters, link-local addresses are usually not
1286+
# usable for communication between compute nodes.
1287+
#
1288+
# Therefore, our order of preference is:
1289+
# 1. Non-link-local IPv4
1290+
# 2. Non-link-local IPv6
1291+
# 3. Link-local IPv4
1292+
# 4. Link-local IPv6
1293+
addrs = getipaddrs()
1294+
i = something(
1295+
findfirst(ip -> !islinklocaladdr(ip) && ip isa IPv4, addrs), # first non-link-local IPv4
1296+
findfirst(ip -> !islinklocaladdr(ip), addrs), # first non-link-local
1297+
findfirst(ip -> ip isa IPv4, addrs), # first IPv4
1298+
1, # first address
1299+
)
1300+
return addrs[i]
12881301
end
12891302

12901303
# initialize the local proc network address / port

0 commit comments

Comments
 (0)