@@ -1278,6 +1278,28 @@ function terminate_all_workers()
12781278 end
12791279end
12801280
1281+ function choose_bind_addr ()
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) && ip isa IPv6, addrs), # first non-link-local IPv6
1297+ findfirst (ip -> ip isa IPv4, addrs), # first IPv4
1298+ findfirst (ip -> ip isa IPv6, addrs), # first IPv6
1299+ )
1300+ return addrs[i]
1301+ end
1302+
12811303# initialize the local proc network address / port
12821304function init_bind_addr ()
12831305 opts = JLOptions ()
@@ -1292,7 +1314,7 @@ function init_bind_addr()
12921314 else
12931315 bind_port = 0
12941316 try
1295- bind_addr = string (getipaddr ())
1317+ bind_addr = string (choose_bind_addr ())
12961318 catch
12971319 # All networking is unavailable, initialize bind_addr to the loopback address
12981320 # Will cause an exception to be raised only when used.
0 commit comments