@@ -1262,6 +1262,28 @@ function terminate_all_workers()
12621262    end 
12631263end 
12641264
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+ 
12651287#  initialize the local proc network address / port
12661288function  init_bind_addr ()
12671289    opts =  JLOptions ()
@@ -1276,7 +1298,7 @@ function init_bind_addr()
12761298    else 
12771299        bind_port =  0 
12781300        try 
1279-             bind_addr =  string (getipaddr ())
1301+             bind_addr =  string (choose_bind_addr ())
12801302        catch 
12811303            #  All networking is unavailable, initialize bind_addr to the loopback address
12821304            #  Will cause an exception to be raised only when used.
0 commit comments