Skip to content

Commit

Permalink
Return socket correctly in socket_reuse_port (#22017)
Browse files Browse the repository at this point in the history
* 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

Ref #22017
(cherry picked from commit d3bc329)
  • Loading branch information
amitmurthy authored and ararslan committed Sep 9, 2017
1 parent f1f50f2 commit ea4b506
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions base/distributed/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ function socket_reuse_port()
return TCPSocket()
end
is_apple() && bind_client_port(s)
return s
else
return TCPSocket()
end
Expand Down
18 changes: 15 additions & 3 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ include("testenv.jl")
end

addprocs_with_testenv(4)
@test nprocs() == 5

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

# Test that the client port is reused. SO_REUSEPORT may not be supported on
# all UNIX platforms, Linux kernels prior to 3.9 and older versions of OSX
if is_unix()
# Run reuse client port tests only if SO_REUSEPORT is supported.
s = TCPSocket(delay = false)
is_linux() && Base.Distributed.bind_client_port(s)
if ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle) == 0
reuseport_tests()
else
info("SO_REUSEPORT is unsupported, skipping reuseport tests.")
end
end

id_me = myid()
id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]

Expand Down

0 comments on commit ea4b506

Please sign in to comment.