Skip to content

Commit

Permalink
don't emit spurious error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Nov 27, 2018
1 parent aeef422 commit 10de262
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ end

Base.showerror(io::IO, e::LaunchWorkerError) = print(io, e.msg)

function read_worker_host_port_throw_error(leader, msg)
for line in leader
println("\tFrom failed worker startup:\t", line)
end
throw(LaunchWorkerError(msg))
end

# The default TCP transport relies on the worker listening on a free
# port available and printing its bind address and port.
# The master process uses this to connect to the worker and subsequently
Expand All @@ -272,40 +279,31 @@ function read_worker_host_port(io::IO)

ntries = 1000
leader = String[]
try
while ntries > 0
readtask = @async readline(io)
yield()
while !istaskdone(readtask) && ((time() - t0) < timeout)
sleep(0.05)
end
!istaskdone(readtask) && break

conninfo = fetch(readtask)
if isempty(conninfo) && !isopen(io)
throw(LaunchWorkerError("Unable to read host:port string from worker. Launch command exited with error?"))
end
while ntries > 0
readtask = @async readline(io)
yield()
while !istaskdone(readtask) && ((time() - t0) < timeout)
sleep(0.05)
end
!istaskdone(readtask) && break

ntries -= 1
bind_addr, port = parse_connection_info(conninfo)
if !isempty(bind_addr)
return bind_addr, port
end
conninfo = fetch(readtask)
isempty(conninfo) && !isopen(io) && read_worker_host_port_throw_error(leader,
"Unable to read host:port string from worker. Launch command exited with error?")

# collect unmatched lines
push!(leader, conninfo)
end
close(io)
if ntries > 0
throw(LaunchWorkerError("Timed out waiting to read host:port string from worker."))
else
throw(LaunchWorkerError("Unexpected output from worker launch command. Host:port string not found."))
end
finally
for line in leader
println("\tFrom failed worker startup:\t", line)
ntries -= 1
bind_addr, port = parse_connection_info(conninfo)
if !isempty(bind_addr)
return bind_addr, port
end

# collect unmatched lines
push!(leader, conninfo)
end
close(io)
read_worker_host_port_throw_error(leader, ntries>0 ?
"Timed out waiting to read host:port string from worker." :
"Unexpected output from worker launch command. Host:port string not found.")
end

function parse_connection_info(str)
Expand Down

0 comments on commit 10de262

Please sign in to comment.