[PR #11289/e38220fc backport][3.13] Fix ClientSession.close() hanging with HTTPS proxy connections#11292
Merged
Dreamsorcerer merged 2 commits into3.13from Jul 9, 2025
Conversation
(cherry picked from commit e38220f)
5 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.13 #11292 +/- ##
==========================================
- Coverage 98.29% 98.29% -0.01%
==========================================
Files 132 132
Lines 43574 43603 +29
Branches 2387 2387
==========================================
+ Hits 42831 42858 +27
- Misses 562 565 +3
+ Partials 181 180 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #11292 will not alter performanceComparing Summary
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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=Nonein the connection key, and theirclosedfutures 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
_ConnectTunnelConnectionclass 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:
Connectionwith a single method overrideRelated issue number
Fixes #11273
Checklist
CONTRIBUTORS.txtCHANGES/folder