Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connectiontimeout to HTTP.request #524

Closed
fonsp opened this issue Mar 23, 2020 · 2 comments
Closed

Add connectiontimeout to HTTP.request #524

fonsp opened this issue Mar 23, 2020 · 2 comments

Comments

@fonsp
Copy link
Member

fonsp commented Mar 23, 2020

Hi! I am looking for a way to limit the connection time for a call to a non-responding server:

HTTP.request("GET", "http://slowwly.robertomurray.co.uk/delay/10000/url/https://julialang.org", retry=false, readtimeout=2)

(This is an API that responds after exactly 10 seconds.) Right now, it will block for 10 seconds - regardless of the readtimeout value.

I understand that this can be done using a ConnectionPool, but I feel like an optional parameter for HTTP.request would be useful. Feel free to close this suggestion if you disagree :)

@fonsp
Copy link
Member Author

fonsp commented Mar 23, 2020

Aha, I found that you can pass connect_timeout=something to HTTP.request, since it will be passed down to getconnection. This actually resulted in a bug:

julia> HTTP.request("GET", "http://slowwly.robertomurray.co.uk/delay/10000/url/https://julialang.org", retry=false, connect_timeout=2)
ERROR: UndefVarError: connect! not defined
Stacktrace:
 [1] #getconnection#14(::Bool, ::Int64, ::Base.Iterators.Pairs{Symbol,Union{Nothing, Bool},Tuple{Symbol,Symbol,Symbol},NamedTuple{(:require_ssl_verification, :iofuncti
on, :retry),Tuple{Bool,Nothing,Bool}}}, ::Function, ::Type{Sockets.TCPSocket}, ::SubString{String}, ::SubString{String}) at /home/fons/.julia/packages/HTTP/facW7/src/C
onnectionPool.jl:622
 [2] #getconnection#10(::Int64, ::Int64, ::Int64, ::Int64, ::Bool, ::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:iofunction, :retry, :conn
ect_timeout),Tuple{Nothing,Bool,Int64}}}, ::Function, ::Type{HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}, ::SubString{String}, ::SubString{String}) at ./none:0
 [3] (::getfield(HTTP.ConnectionPool, Symbol("#kw##getconnection")))(::NamedTuple{(:reuse_limit, :iofunction, :retry, :connect_timeout),Tuple{Int64,Nothing,Bool,Int64}
}, ::typeof(HTTP.ConnectionPool.getconnection), ::Type{HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}, ::SubString{String}, ::SubString{String}) at ./none:0
 [4] #request#1(::Nothing, ::Type, ::Int64, ::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:iofunction, :retry, :connect_timeout),Tuple{Noth
ing,Bool,Int64}}}, ::Function, ::Type{ConnectionPoolLayer{StreamLayer{Union{}}}}, ::HTTP.URIs.URI, ::HTTP.Messages.Request, ::Array{UInt8,1}) at /home/fons/.julia/pack
ages/HTTP/facW7/src/ConnectionRequest.jl:73
 [5] (::getfield(HTTP, Symbol("#kw##request")))(::NamedTuple{(:iofunction, :retry, :connect_timeout),Tuple{Nothing,Bool,Int64}}, ::typeof(HTTP.request), ::Type{Connect
ionPoolLayer{StreamLayer{Union{}}}}, ::HTTP.URIs.URI, ::HTTP.Messages.Request, ::Array{UInt8,1}) at ./none:0
 [6] #request#1(::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:iofunction, :retry, :connect_timeout),Tuple{Nothing,Bool,Int64}}}, ::Functio
n, ::Type{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}, ::HTTP.URIs.URI, ::Vararg{Any,N} where N) at /home/fons/.julia/packages/HTTP/facW7/src/ExceptionR
equest.jl:19
 [7] #request at ./none:0 [inlined]
 [8] #request#1(::VersionNumber, ::String, ::Nothing, ::Nothing, ::Base.Iterators.Pairs{Symbol,Integer,Tuple{Symbol,Symbol},NamedTuple{(:retry, :connect_timeout),Tuple
{Bool,Int64}}}, ::Function, ::Type{MessageLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}, ::String, ::HTTP.URIs.URI, ::Array{Pair{SubString{String},
SubString{String}},1}, ::Array{UInt8,1}) at /home/fons/.julia/packages/HTTP/facW7/src/MessageRequest.jl:51
 [9] #request at ./none:0 [inlined]
 [10] #request#1(::Base.Iterators.Pairs{Symbol,Integer,Tuple{Symbol,Symbol},NamedTuple{(:retry, :connect_timeout),Tuple{Bool,Int64}}}, ::Function, ::Type{BasicAuthLaye
r{MessageLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}, ::String, ::HTTP.URIs.URI, ::Array{Pair{SubString{String},SubString{String}},1}, ::Array{U
Int8,1}) at /home/fons/.julia/packages/HTTP/facW7/src/BasicAuthRequest.jl:28
 [11] (::getfield(HTTP, Symbol("#kw##request")))(::NamedTuple{(:retry, :connect_timeout),Tuple{Bool,Int64}}, ::typeof(HTTP.request), ::Type{BasicAuthLayer{MessageLayer
{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}, ::String, ::HTTP.URIs.URI, ::Array{Pair{SubString{String},SubString{String}},1}, ::Array{UInt8,1}) at ./
none:0
 [12] #request#1(::Int64, ::Bool, ::Base.Iterators.Pairs{Symbol,Integer,Tuple{Symbol,Symbol},NamedTuple{(:retry, :connect_timeout),Tuple{Bool,Int64}}}, ::Function, ::T
ype{RedirectLayer{BasicAuthLayer{MessageLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}}, ::String, ::HTTP.URIs.URI, ::Array{Pair{SubString{String},
SubString{String}},1}, ::Array{UInt8,1}) at /home/fons/.julia/packages/HTTP/facW7/src/RedirectRequest.jl:24
 [13] (::getfield(HTTP, Symbol("#kw##request")))(::NamedTuple{(:retry, :connect_timeout),Tuple{Bool,Int64}}, ::typeof(HTTP.request), ::Type{RedirectLayer{BasicAuthLaye
r{MessageLayer{ExceptionLayer{ConnectionPoolLayer{StreamLayer{Union{}}}}}}}}, ::String, ::HTTP.URIs.URI, ::Array{Pair{SubString{String},SubString{String}},1}, ::Array{
UInt8,1}) at ./none:0
 [14] #request#4(::Array{Pair{SubString{String},SubString{String}},1}, ::Array{UInt8,1}, ::Nothing, ::Base.Iterators.Pairs{Symbol,Integer,Tuple{Symbol,Symbol},NamedTup
le{(:retry, :connect_timeout),Tuple{Bool,Int64}}}, ::Function, ::String, ::String, ::Array{Pair{SubString{String},SubString{String}},1}, ::Array{UInt8,1}) at /home/fon
s/.julia/packages/HTTP/facW7/src/HTTP.jl:314
 [15] #request at ./none:0 [inlined] (repeats 2 times)
 [16] top-level scope at none:0

which is fixed by this PR: #525

@quinnj
Copy link
Member

quinnj commented Oct 9, 2020

Closing as fixed/dup of #221 to document connect_timeout

@quinnj quinnj closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants