Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return socket correctly in socket_reuse_port #22017

Merged
merged 3 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/distributed/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,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