Skip to content

Commit 464b53c

Browse files
authored
Ensure connect_timeout doesn't count acquire time on the connection pool (#1075)
* Ensure connect_timeout doesn't count acquire time on the connection pool * Fix connect_timeout defaults/docs
1 parent ba72cbd commit 464b53c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/Connections.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ function newconnection(::Type{T},
446446
connection_limit=nothing,
447447
forcenew::Bool=false,
448448
idle_timeout=typemax(Int),
449+
connect_timeout::Int=30,
449450
require_ssl_verification::Bool=NetworkOptions.verify_host(host, "SSL"),
450451
keepalive::Bool=true,
451452
kw...) where {T <: IO}
@@ -457,8 +458,13 @@ function newconnection(::Type{T},
457458
isvalid=c->connection_isvalid(c, Int(idle_timeout))) do
458459
Connection(host, port,
459460
idle_timeout, require_ssl_verification, keepalive,
460-
getconnection(T, host, port;
461-
require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...)
461+
connect_timeout > 0 ?
462+
try_with_timeout(_ ->
463+
getconnection(T, host, port;
464+
require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...),
465+
connect_timeout) :
466+
getconnection(T, host, port;
467+
require_ssl_verification=require_ssl_verification, keepalive=keepalive, kw...)
462468
)
463469
end
464470
end

src/HTTP.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Supported optional keyword arguments:
137137
will be written to this stream instead of returned as a `Vector{UInt8}`.
138138
- `verbose = 0`, set to `1` or `2` for increasingly verbose logging of the
139139
request and response process
140-
- `connect_timeout = 10`, close the connection after this many seconds if it
140+
- `connect_timeout = 30`, close the connection after this many seconds if it
141141
is still attempting to connect. Use `connect_timeout = 0` to disable.
142142
- `pool = nothing`, an `HTTP.Pool` object to use for managing the reuse of connections between requests.
143143
By default, a global pool is used, which is shared across all requests. To create a pool for a specific set of requests,

src/clientlayers/ConnectionRequest.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Close the connection if the request throws an exception.
5555
Otherwise leave it open so that it can be reused.
5656
"""
5757
function connectionlayer(handler)
58-
return function connections(req; proxy=getproxy(req.url.scheme, req.url.host), socket_type::Type=TCPSocket, socket_type_tls::Type=SOCKET_TYPE_TLS[], readtimeout::Int=0, connect_timeout::Int=60, logerrors::Bool=false, logtag=nothing, kw...)
58+
return function connections(req; proxy=getproxy(req.url.scheme, req.url.host), socket_type::Type=TCPSocket, socket_type_tls::Type=SOCKET_TYPE_TLS[], readtimeout::Int=0, connect_timeout::Int=30, logerrors::Bool=false, logtag=nothing, kw...)
5959
local io, stream
6060
if proxy !== nothing
6161
target_url = req.url
@@ -77,13 +77,7 @@ function connectionlayer(handler)
7777
IOType = sockettype(url, socket_type, socket_type_tls)
7878
start_time = time()
7979
try
80-
io = if connect_timeout > 0
81-
try_with_timeout(connect_timeout) do _
82-
newconnection(IOType, url.host, url.port; readtimeout=readtimeout, kw...)
83-
end
84-
else
85-
newconnection(IOType, url.host, url.port; readtimeout=readtimeout, kw...)
86-
end
80+
io = newconnection(IOType, url.host, url.port; readtimeout=readtimeout, connect_timeout=connect_timeout, kw...)
8781
catch e
8882
if logerrors
8983
err = current_exceptions_to_string()

0 commit comments

Comments
 (0)