[PR #11289/e38220fc backport][3.13] Fix ClientSession.close() hanging with HTTPS proxy connections #11292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #11289 as merged into master (e38220f).
What do these changes do?
This PR fixes a regression where
ClientSession.close()
would hang indefinitely when HTTPS requests were made through an HTTP proxy. The issue was caused by CONNECT tunnel connections being pooled withproxy=None
in the connection key, and theirclosed
futures never completing. The leaking connections have been an issue for some time, but only became apparent when we fixed the waiting issue in 3.12.4.The fix introduces a special
_ConnectTunnelConnection
class that overrides therelease()
method to prevent these connections from being pooled. This allows the connections to be properly used for TLS upgrade without interfering with session cleanup.Are there changes in behavior for the user?
Users will no longer experience hanging when calling
session.close()
after making HTTPS requests through HTTP proxies. The behavior is restored to how it worked before we started waiting for the connections to close. They had been leaking into the connection pool for some time.Is it a substantial burden for the maintainers to support this?
No. The fix is minimal and isolated:
Connection
with a single method overrideRelated issue number
Fixes #11273
Checklist
CONTRIBUTORS.txt
CHANGES/
folder