@@ -1278,6 +1278,28 @@ function terminate_all_workers()
1278
1278
end
1279
1279
end
1280
1280
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
+
1281
1303
# initialize the local proc network address / port
1282
1304
function init_bind_addr ()
1283
1305
opts = JLOptions ()
@@ -1292,7 +1314,7 @@ function init_bind_addr()
1292
1314
else
1293
1315
bind_port = 0
1294
1316
try
1295
- bind_addr = string (getipaddr ())
1317
+ bind_addr = string (choose_bind_addr ())
1296
1318
catch
1297
1319
# All networking is unavailable, initialize bind_addr to the loopback address
1298
1320
# Will cause an exception to be raised only when used.
0 commit comments