Skip to content

Commit c0e9eb4

Browse files
authored
Factor functionality out into separate choose_bind_addr() function
1 parent 86cbb8a commit c0e9eb4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cluster.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,15 @@ function terminate_all_workers()
12781278
end
12791279
end
12801280

1281+
function choose_bind_addr()
1282+
# On HPC clusters, link-local addresses are usually not usable for
1283+
# communication between compute nodes.
1284+
# 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+
end
1289+
12811290
# initialize the local proc network address / port
12821291
function init_bind_addr()
12831292
opts = JLOptions()
@@ -1292,12 +1301,7 @@ function init_bind_addr()
12921301
else
12931302
bind_port = 0
12941303
try
1295-
# On HPC clusters, link-local addresses are usually not usable for
1296-
# communication between compute nodes.
1297-
# Therefore, we use the first non-link-local IPv4 address.
1298-
addrs = Sockets.getipaddrs(Sockets.IPv4)
1299-
filter!(!Sockets.islinklocaladdr, addrs)
1300-
bind_addr = string(first(addrs))
1304+
bind_addr = string(choose_bind_addr())
13011305
catch
13021306
# All networking is unavailable, initialize bind_addr to the loopback address
13031307
# Will cause an exception to be raised only when used.

0 commit comments

Comments
 (0)