Skip to content

Commit

Permalink
Sockets: handle ECANCELED result from connect (#26545)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Mar 22, 2018
1 parent c38298a commit ef0ef80
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4ebb4a23eb48e4ae6658c9cfc508f914
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b90c11d208245e1cf9d99288f102e4c19a8a8a4d2e01777a7bc3c9674f125ade5934f94cefac695178333d7737166825cb2d7c7085b0993b90eb45cab115fa56
2 changes: 1 addition & 1 deletion deps/libuv.version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
LIBUV_BRANCH=julia-uv2
LIBUV_SHA1=80caa0b133fbadd322dad52bcddd2933b3b803f7
LIBUV_SHA1=9ea9136dee3f0496edc1b9b4fe9825c391c4c889
7 changes: 4 additions & 3 deletions stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,13 @@ end
function uv_connectcb(conn::Ptr{Cvoid}, status::Cint)
hand = ccall(:jl_uv_connect_handle, Ptr{Cvoid}, (Ptr{Cvoid},), conn)
sock = @handle_as hand LibuvStream
@assert sock.status == StatusConnecting
if status >= 0
sock.status = StatusOpen
if !(sock.status == StatusClosed || sock.status == StatusClosing)
sock.status = StatusOpen
end
notify(sock.connectnotify)
else
sock.status = StatusInit
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), hand)
err = UVError("connect", status)
notify_error(sock.connectnotify, err)
end
Expand Down
46 changes: 24 additions & 22 deletions stdlib/Sockets/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,30 +397,32 @@ end
@testset "connect!" begin
# test the method matching connect!(::TCPSocket, ::Sockets.InetAddr{T<:Base.IPAddr})
let addr = Sockets.InetAddr(ip"127.0.0.1", 4444)

function test_connect(addr::Sockets.InetAddr)
srv = listen(addr)

@async try c = accept(srv); close(c) catch end
yield()

t0 = TCPSocket()
t = t0
@assert t === t0

try
t = connect(addr)
finally
close(srv)
end

test = t !== t0
close(t)

return test
srv = listen(addr)
c = Condition()
r = @schedule try; close(accept(srv)); finally; notify(c); end
try
close(connect(addr))
fetch(c)
finally
close(srv)
end
fetch(r)
end

@test test_connect(addr)
let addr = Sockets.InetAddr(ip"127.0.0.1", 4444)
srv = listen(addr)
r = @schedule close(srv)
@test_throws Base.UVError("accept", Base.UV_ECONNABORTED) accept(srv)
fetch(r)
end

let addr = Sockets.InetAddr(ip"127.0.0.1", 4444)
srv = listen(addr)
s = Sockets.TCPSocket()
Sockets.connect!(s, addr)
r = @schedule close(s)
@test_throws Base.UVError("connect", Base.UV_ECANCELED) Sockets.wait_connected(s)
fetch(r)
end
end

Expand Down

0 comments on commit ef0ef80

Please sign in to comment.