Skip to content

Commit 99e7780

Browse files
authored
Non-link-local IP4 > non-link-local IP6 > link-local IP4 > link-local IP6
1 parent c0e9eb4 commit 99e7780

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/cluster.jl

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

12811281
function choose_bind_addr()
1282-
# On HPC clusters, link-local addresses are usually not usable for
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 usable for
12831286
# communication between compute nodes.
12841287
# 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)
1288+
#
1289+
# Therefore, our order of preference is:
1290+
# 1. Non-link-local IPv4
1291+
# 2. Non-link-local IPv6
1292+
# 3. Link-local IPv4
1293+
# 4. Link-local IPv6
1294+
addrs = getipaddrs()
1295+
i = something(
1296+
findfirst(ip -> ip isa IPv4 && !islinklocaladdr(ip), addrs), # first non-link-local IPv4
1297+
findfirst(ip -> !islinklocaladdr(ip), addrs), # first non-link-local
1298+
findfirst(ip -> ip isa IPv4, addrs), # first IPv4
1299+
1, # first address
1300+
)
1301+
return addrs[i]
12881302
end
12891303

12901304
# initialize the local proc network address / port

0 commit comments

Comments
 (0)