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

Keep self.pools.lock acquired until ConnectionPool calls _get_conn #1263

Closed
wants to merge 1 commit into from

Conversation

reversefold
Copy link
Contributor

@reversefold reversefold commented Sep 6, 2017

Fixes issue #1262
Part of PR #1257

This PR keeps PoolManager.pools.lock acquired until HTTPConnectionPool.urlopen calls _get_conn. This should close the race condition for any request which does not have Retry-After.

I would like to find a better way to do this but this fix is small enough that I feel it should be fine for an initial attempt.


This change is Reviewable

@codecov-io
Copy link

codecov-io commented Sep 9, 2017

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1263   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          21      21           
  Lines        1985    1992    +7     
======================================
+ Hits         1985    1992    +7
Impacted Files Coverage Δ
urllib3/poolmanager.py 100% <100%> (ø) ⬆️
urllib3/connectionpool.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 dfc23e5...d25f930. Read the comment docs.

@reversefold
Copy link
Contributor Author

Rebased on master so the gae test should work.

@reversefold
Copy link
Contributor Author

Rebased on master again.

@reversefold
Copy link
Contributor Author

Here are all of the tests passing on travis-ci: https://travis-ci.org/reversefold/urllib3/builds/274031847

Copy link
Sponsor 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.

So I don't love this patch. 😞

Ultimately this passing around of arbitrary locks is not a great strategy for managing this. It would be better, if we can, to split urlopen into two functions that can be called separately, such that we can manage the locking appropriately.

For backward-compat we'll need to keep urlopen, but it should be possible to reimplement it in terms of the two underlying functions.

How does that sound?

@reversefold
Copy link
Contributor Author

That sounds fine, this was just a smaller patch I could send that fixed this particular issue. I actually meant it as a short-term workaround until some refactoring could be done. I'll try to get the rest of my refactoring made into one or more patches then try to reimplement this one.

@sethmlarson
Copy link
Member

I'm closing this PR due to staleness (see #1370) if you want this to get merged still I'll reopen following an update to this patch. Thanks!

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

4 participants