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

Document connect_timeout and set it to the nonzero minimum of itself and readtimeout #641

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

sean-bennett112
Copy link
Contributor

This is to make it the same format as readtimeout.

Also changes connecttimeout to be the nonzero minimum of connecttimeout and readtimeout if either is set.

This is to get around connections hanging even if readtimeout is set. For example, this occurs if you try to connect to the EC2 metadata IP from outside AWS.

I'm not sure of a great way to add a test for this. This works, for example:

@test_throws Exception HTTP.get("http://169.254.169.254/latest/meta-data/iam/info"; connectiontimeout=1, retry=false)

But I'd obviously prefer to avoid trying to hit the EC2 metadata service.

This is to make it the same format as `readtimeout`.

Also changes `connecttimeout` to be the nonzero minimum of
`connecttimeout` and `readtimeout` if either is set.

This is to get around connections hanging even if
`readtimeout` is set. For example, this occurs if you try
to connect to the EC2 metadata IP from outside AWS.
@codecov-io
Copy link

codecov-io commented Dec 8, 2020

Codecov Report

Merging #641 (e2aae2e) into master (a91ec98) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #641      +/-   ##
==========================================
+ Coverage   77.53%   77.55%   +0.01%     
==========================================
  Files          36       36              
  Lines        2324     2326       +2     
==========================================
+ Hits         1802     1804       +2     
  Misses        522      522              
Impacted Files Coverage Δ
src/HTTP.jl 100.00% <ø> (ø)
src/ConnectionPool.jl 77.95% <100.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a91ec98...c63b4bb. Read the comment docs.

Comment on lines 651 to 652
timeouts = filter(!iszero, [connect_timeout, readtimeout])
connect_timeout = isempty(timeouts) ? 0 : minimum(timeouts)
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be just

Suggested change
timeouts = filter(!iszero, [connect_timeout, readtimeout])
connect_timeout = isempty(timeouts) ? 0 : minimum(timeouts)
connect_timeout = min(connect_timeout, readtimeout)

Copy link
Member

Choose a reason for hiding this comment

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

No, because we want the smallest non-zero between the two. It could be:

connect_timeout = minimum(filter(!iszero, [connect_timeout, readtimeout]))

Wait no. If both are 0 this will break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe so. If either connect_timeout or readtimeout is 0, then that will return 0, meaning no connection timeout will be set.

Copy link
Member

Choose a reason for hiding this comment

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

How about just:

connect_timeout = connect_timeout == 0 && readtimeout > 0 ? readtimeout : connect_timeout

That avoids allocating an unnecessary array and the need to call filter and minimum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I like that better, fixed.

@sean-bennett112 sean-bennett112 changed the title Change connect_timeout to connecttimeout and document Document connect_timeout and set it to the nonzero minimum of itself and readtimeout Dec 8, 2020
src/HTTP.jl Outdated Show resolved Hide resolved
Comment on lines 651 to 652
timeouts = filter(!iszero, [connect_timeout, readtimeout])
connect_timeout = isempty(timeouts) ? 0 : minimum(timeouts)
Copy link
Member

Choose a reason for hiding this comment

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

How about just:

connect_timeout = connect_timeout == 0 && readtimeout > 0 ? readtimeout : connect_timeout

That avoids allocating an unnecessary array and the need to call filter and minimum.

@quinnj quinnj merged commit 10cdfd4 into JuliaWeb:master Dec 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

Successfully merging this pull request may close these issues.

None yet

5 participants