Skip to content

Commit

Permalink
Merge pull request #580 from JuliaWeb/jq/proxyclose2
Browse files Browse the repository at this point in the history
Ensure https proxy connections don't clog up the ConnectionPool
  • Loading branch information
quinnj authored Sep 16, 2020
2 parents fb81a08 + d2ffc1a commit b127f4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
17 changes: 17 additions & 0 deletions src/ConnectionPool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,22 @@ function release(c::Connection)
return
end

# "release" a Connection, without returning to pod for re-use
# used for https proxy tunnel upgrades which shouldn't be reused
function kill!(c::Connection)
h = hashconn(c)
if haskey(POOL.conns, h)
pod = getpod(POOL, h)
@v1_3 lock(pod.conns)
try
decr!(pod)
finally
@v1_3 unlock(pod.conns)
end
end
return
end

struct Pool
lock::ReentrantLock
conns::Dict{UInt, Pod}
Expand Down Expand Up @@ -692,6 +708,7 @@ function sslupgrade(t::Transaction{TCPSocket},
require_ssl_verification=require_ssl_verification,
kw...)
c = Connection(tls; require_ssl_verification=require_ssl_verification)
kill!(t.c)
return client_transaction(c)
end

Expand Down
25 changes: 11 additions & 14 deletions src/ConnectionRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body;

try
if proxy !== nothing && target_url.scheme == "https"
# tunnel request
target_url = merge(target_url, port=443)
return tunnel_request(Next, io, target_url, req, body; kw...)
r = connect_tunnel(io, target_url, req)
if r.status != 200
close(io)
return r
end
io = ConnectionPool.sslupgrade(io, target_url.host; kw...)
req.headers = filter(x->x.first != "Proxy-Authorization", req.headers)
end

r = request(Next, io, req, body; kw...)

if (io.sequence >= reuse_limit
|| (proxy !== nothing && target_url.scheme == "https"))
|| (proxy !== nothing && target_url.scheme == "https"))
println("HERE")
close(io)
end

Expand All @@ -102,18 +110,7 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body;

end

sockettype(url::URI, default) = url.scheme in ("wss", "https") ? SSLContext :
default

function tunnel_request(Next, io, target_url, req, body; kw...)
r = connect_tunnel(io, target_url, req)
if r.status != 200
return r
end
io = ConnectionPool.sslupgrade(io, target_url.host; kw...)
req.headers = filter(x->x.first != "Proxy-Authorization", req.headers)
return request(Next, io, req, body; kw...)
end
sockettype(url::URI, default) = url.scheme in ("wss", "https") ? SSLContext : default

function connect_tunnel(io, target_url, req)
target = "$(URIs.hoststring(target_url.host)):$(target_url.port)"
Expand Down

2 comments on commit b127f4d

@quinnj
Copy link
Member Author

@quinnj quinnj commented on b127f4d Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/21460

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.18 -m "<description of version>" b127f4d17c42160ec0b7b28d46349bb2e509991e
git push origin v0.8.18

Please sign in to comment.