Skip to content

Commit

Permalink
Don't require getting IO lock within connect lock
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Jul 12, 2023
1 parent aa30905 commit 9c78cbd
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,16 @@ function getconnection(::Type{TCPSocket},
for addr in addrs
Threads.@spawn begin
try
isready(ch) && return
tcp = Sockets.connect($addr, p)
Base.@lock ch begin
if isready(ch)
# a valid connection was already made and returned, so close ours
close(tcp)
return
if !isready(ch)
tcp = Sockets.connect($addr, p)
Base.@lock ch begin
if isready(ch)
# a valid connection was already made and returned, so close ours
close(tcp)
else
put!(ch, tcp)
end
end
keepalive && keepalive!(tcp)
put!(ch, tcp)
end
catch e
Base.@lock ch begin
Expand All @@ -540,7 +540,9 @@ function getconnection(::Type{TCPSocket},
end
end
end
return fetch(ch)
sock = fetch(ch)
keepalive && keepalive!(sock)
return sock
end

const nosslconfig = SSLConfig()
Expand Down

0 comments on commit 9c78cbd

Please sign in to comment.