Skip to content

Release connection on chunked HEAD response.#1235

Merged
Lukasa merged 1 commit intourllib3:masterfrom
timuralp:bug/chunked-head
Jul 22, 2017
Merged

Release connection on chunked HEAD response.#1235
Lukasa merged 1 commit intourllib3:masterfrom
timuralp:bug/chunked-head

Conversation

@timuralp
Copy link
Copy Markdown
Contributor

AWS S3 servers set "Transfer-Encoding: chunked" even for a HEAD
response, which results in urllib3 not returning the connection to the
pool after calling stream() or read_chunked().

The patch moves the HEAD request check into the error_catcher context
manager, which ensures to release the connection to the pool upon
completion.

Fixes #1234

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 21, 2017

Codecov Report

Merging #1235 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1235   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          21      21           
  Lines        1985    1985           
======================================
  Hits         1985    1985
Impacted Files Coverage Δ
urllib3/response.py 100% <100%> (ø) ⬆️

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 33f4bda...3296c81. Read the comment docs.

Copy link
Copy Markdown
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Cool, well spotted. This is definitely not handled correctly. With some minor cleanups to the test I think this should be totally fine.

Comment thread test/test_response.py Outdated
def __init__(self):
self.released = False

track_release = TrackRelease()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than use this inner class we can save ourselves some time and just store the calls in a list. Alternatively, you can use the mock module directly, which may be the best approach.

@Lukasa
Copy link
Copy Markdown
Contributor

Lukasa commented Jul 21, 2017

Can you also add a CHANGES.rst entry for this?

@timuralp
Copy link
Copy Markdown
Contributor Author

Done -- didn't notice the mock module being used earlier. That's definitely the cleaner way to test it.

Copy link
Copy Markdown
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Cool, looks much better. One small inline note: also, can you bring this branch up-to-date with the current master?

Comment thread CHANGES.rst

* Put the connection back in the pool when calling stream() or read_chunked() on
a chunked HEAD response. (Issue #1234)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you put this above the placeholder instead of below?

AWS S3 servers set "Transfer-Encoding: chunked" even for a HEAD
response, which results in urllib3 not returning the connection to the
pool after calling stream() or read_chunked().

The patch moves the HEAD request check into the error_catcher context
manager, which ensures to release the connection to the pool upon
completion.

Fixes urllib3#1234
@timuralp
Copy link
Copy Markdown
Contributor Author

Done -- rebased and moved the CHANGES.rst entry.

Copy link
Copy Markdown
Contributor

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

This looks good to me! Merge when you're satisfied @Lukasa :)

@sigmavirus24
Copy link
Copy Markdown
Contributor

@timuralp say "hi" to the folks at SwiftStack for me. Haven't spoken to any of them in a long time. 😄

@Lukasa Lukasa merged commit de81455 into urllib3:master Jul 22, 2017
@Lukasa
Copy link
Copy Markdown
Contributor

Lukasa commented Jul 22, 2017

Thanks for this @timuralp!

@peterbe
Copy link
Copy Markdown

peterbe commented Aug 17, 2017

For the record, I spent an afternoon debugging requests and urllib3 and tonnes of googling trying to figure out why new HTTPS connections had to be set up after a session.head(url) when the URL was an S3 URL that always 404s.

This PR totally fixes. I've compared (roughly 300 requests) using urllib3==1.22 versus urllib3@de81455 and the median time it takes to asset session.head(url).status_code==404 went from 0.55 seconds to 0.13 seconds here on my home broadband (which is pretty fast).

So yay!!

@timuralp timuralp deleted the bug/chunked-head branch August 17, 2017 20:56
Dobatymo pushed a commit to Dobatymo/urllib3 that referenced this pull request Mar 16, 2022
Release connection on chunked HEAD response.
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.

5 participants