Skip to content

Commit d3bc329

Browse files
authored
Return socket correctly in socket_reuse_port (#22017)
* Return socket correctly in socket_reuse_port * Run reuseport tests only if SO_REUSEPORT is supported. * Test fix - test for successful addition of workers in distributed test
1 parent 7523a43 commit d3bc329

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

base/distributed/managers.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ function socket_reuse_port()
471471
return TCPSocket()
472472
end
473473
is_apple() && bind_client_port(s)
474+
return s
474475
else
475476
return TCPSocket()
476477
end

test/distributed_exec.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ include("testenv.jl")
1111
end
1212

1313
addprocs_with_testenv(4)
14+
@test nprocs() == 5
1415

15-
# Test that the client port is reused. SO_REUSEPORT may not be supported on
16-
# all UNIX platforms, Linux kernels prior to 3.9 and older versions of OSX
17-
if is_unix()
16+
function reuseport_tests()
1817
# Run the test on all processes.
1918
results = asyncmap(procs()) do p
2019
remotecall_fetch(p) do
@@ -47,6 +46,19 @@ if is_unix()
4746
@test all(p -> p in results, procs())
4847
end
4948

49+
# Test that the client port is reused. SO_REUSEPORT may not be supported on
50+
# all UNIX platforms, Linux kernels prior to 3.9 and older versions of OSX
51+
if is_unix()
52+
# Run reuse client port tests only if SO_REUSEPORT is supported.
53+
s = TCPSocket(delay = false)
54+
is_linux() && Base.Distributed.bind_client_port(s)
55+
if ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle) == 0
56+
reuseport_tests()
57+
else
58+
info("SO_REUSEPORT is unsupported, skipping reuseport tests.")
59+
end
60+
end
61+
5062
id_me = myid()
5163
id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]
5264

0 commit comments

Comments
 (0)