Skip to content

Conversation

patchback[bot]
Copy link
Contributor

@patchback patchback bot commented Jul 9, 2025

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 with proxy=None in the connection key, and their closed 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 the release() 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:

  • Adds a small subclass of Connection with a single method override
  • Only affects CONNECT tunnel connections for HTTPS through HTTP proxies
  • Includes comprehensive tests to prevent regression
  • The special handling is clearly documented in the code

Related issue number

Fixes #11273

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes (no user-facing API changes)
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.29%. Comparing base (41115b7) to head (6e957de).
Report is 1 commits behind head on 3.13.

✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
CI-GHA 98.18% <100.00%> (-0.01%) ⬇️
OS-Linux 97.93% <100.00%> (-0.01%) ⬇️
OS-Windows 95.64% <100.00%> (-0.01%) ⬇️
OS-macOS 97.17% <100.00%> (-0.01%) ⬇️
Py-3.10.11 96.82% <96.66%> (+<0.01%) ⬆️
Py-3.10.18 97.30% <96.66%> (-0.01%) ⬇️
Py-3.11.13 97.50% <96.66%> (-0.02%) ⬇️
Py-3.11.9 97.01% <96.66%> (-0.01%) ⬇️
Py-3.12.10 97.10% <96.66%> (-0.01%) ⬇️
Py-3.12.11 97.60% <96.66%> (+<0.01%) ⬆️
Py-3.13.3 97.83% <96.66%> (+<0.01%) ⬆️
Py-3.9.13 96.71% <100.00%> (+<0.01%) ⬆️
Py-3.9.23 97.20% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 86.37% <100.00%> (-1.28%) ⬇️
VM-macos 97.17% <100.00%> (-0.01%) ⬇️
VM-ubuntu 97.93% <100.00%> (-0.01%) ⬇️
VM-windows 95.64% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Jul 9, 2025

CodSpeed Performance Report

Merging #11292 will not alter performance

Comparing patchback/backports/3.13/e38220fc4ed59c9de0dbe23da48e9cfd287c2ed7/pr-11289 (6e957de) with 3.13 (41115b7)

Summary

✅ 59 untouched benchmarks

@Dreamsorcerer Dreamsorcerer merged commit 8790eb0 into 3.13 Jul 9, 2025
61 of 65 checks passed
@Dreamsorcerer Dreamsorcerer deleted the patchback/backports/3.13/e38220fc4ed59c9de0dbe23da48e9cfd287c2ed7/pr-11289 branch July 9, 2025 23:41
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.

2 participants