@@ -1262,6 +1262,28 @@ function terminate_all_workers()
1262
1262
end
1263
1263
end
1264
1264
1265
+ function choose_bind_addr ()
1266
+ # We prefer IPv4 over IPv6.
1267
+ #
1268
+ # We also prefer non-link-local over link-local.
1269
+ # (This is because on HPC clusters, link-local addresses are usually not
1270
+ # usable for communication between compute nodes.
1271
+ #
1272
+ # Therefore, our order of preference is:
1273
+ # 1. Non-link-local IPv4
1274
+ # 2. Non-link-local IPv6
1275
+ # 3. Link-local IPv4
1276
+ # 4. Link-local IPv6
1277
+ addrs = getipaddrs ()
1278
+ i = something (
1279
+ findfirst (ip -> ! islinklocaladdr (ip) && ip isa IPv4, addrs), # first non-link-local IPv4
1280
+ findfirst (ip -> ! islinklocaladdr (ip) && ip isa IPv6, addrs), # first non-link-local IPv6
1281
+ findfirst (ip -> ip isa IPv4, addrs), # first IPv4
1282
+ findfirst (ip -> ip isa IPv6, addrs), # first IPv6
1283
+ )
1284
+ return addrs[i]
1285
+ end
1286
+
1265
1287
# initialize the local proc network address / port
1266
1288
function init_bind_addr ()
1267
1289
opts = JLOptions ()
@@ -1276,7 +1298,7 @@ function init_bind_addr()
1276
1298
else
1277
1299
bind_port = 0
1278
1300
try
1279
- bind_addr = string (getipaddr ())
1301
+ bind_addr = string (choose_bind_addr ())
1280
1302
catch
1281
1303
# All networking is unavailable, initialize bind_addr to the loopback address
1282
1304
# Will cause an exception to be raised only when used.
0 commit comments