Skip to content

Commit

Permalink
fix #32903, regression in Ctrl-C after adding io locks (#33031)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 26, 2019
1 parent 0c209e2 commit 7d65e13
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function wait(c::GenericCondition)
try
return wait()
catch
list_deletefirst!(c.waitq, ct)
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
rethrow()
finally
relockall(c.lock, token)
Expand Down
5 changes: 5 additions & 0 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -924,15 +924,20 @@ function uv_write(s::LibuvStream, p::Ptr{UInt8}, n::UInt)
uvw = uv_write_async(s, p, n)
ct = current_task()
preserve_handle(ct)
sigatomic_begin()
uv_req_set_data(uvw, ct)
iolock_end()
status = try
sigatomic_end()
# wait for the last chunk to complete (or error)
# assume that any errors would be sticky,
# (so we don't need to monitor the error status of the intermediate writes)
wait()::Cint
finally
# try-finally unwinds the sigatomic level, so need to repeat sigatomic_end
sigatomic_end()
iolock_begin()
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
if uv_req_data(uvw) != C_NULL
# uvw is still alive,
# so make sure we won't get spurious notifications later
Expand Down
11 changes: 10 additions & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,16 @@ Switch to the scheduler to allow another scheduled task to run. A task that call
function is still runnable, and will be restarted immediately if there are no other runnable
tasks.
"""
yield() = (enq_work(current_task()); wait())
function yield()
ct = current_task()
enq_work(ct)
try
wait()
catch
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
rethrow()
end
end

"""
yield(t::Task, arg = nothing)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,16 @@ function send(sock::UDPSocket, ipaddr::IPAddr, port::Integer, msg)
uvw = _send_async(sock, ipaddr, UInt16(port), msg)
ct = current_task()
preserve_handle(ct)
Base.sigatomic_begin()
uv_req_set_data(uvw, ct)
iolock_end()
status = try
Base.sigatomic_end()
wait()::Cint
finally
Base.sigatomic_end()
iolock_begin()
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
if uv_req_data(uvw) != C_NULL
# uvw is still alive,
# so make sure we won't get spurious notifications later
Expand Down
12 changes: 12 additions & 0 deletions stdlib/Sockets/src/addrinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ function getalladdrinfo(host::String)
end
ct = current_task()
preserve_handle(ct)
Base.sigatomic_begin()
uv_req_set_data(req, ct)
iolock_end()
r = try
Base.sigatomic_end()
wait()
finally
Base.sigatomic_end()
iolock_begin()
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
if uv_req_data(req) != C_NULL
# req is still alive,
# so make sure we don't get spurious notifications later
Expand All @@ -87,6 +92,7 @@ function getalladdrinfo(host::String)
# done with req
Libc.free(req)
end
iolock_end()
unpreserve_handle(ct)
end
if isa(r, IOError)
Expand Down Expand Up @@ -176,11 +182,16 @@ function getnameinfo(address::Union{IPv4, IPv6})
end
ct = current_task()
preserve_handle(ct)
Base.sigatomic_begin()
uv_req_set_data(req, ct)
iolock_end()
r = try
Base.sigatomic_end()
wait()
finally
Base.sigatomic_end()
iolock_begin()
ct.queue === nothing || list_deletefirst!(ct.queue, ct)
if uv_req_data(req) != C_NULL
# req is still alive,
# so make sure we don't get spurious notifications later
Expand All @@ -190,6 +201,7 @@ function getnameinfo(address::Union{IPv4, IPv6})
# done with req
Libc.free(req)
end
iolock_end()
unpreserve_handle(ct)
end
if isa(r, IOError)
Expand Down

0 comments on commit 7d65e13

Please sign in to comment.