Jump to solution
Verify

The Fix

Fixes a regression where ClientSession.close() would hang indefinitely when HTTPS requests were made through an HTTP proxy.

Based on closed aio-libs/aiohttp issue #11273 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Fixed :py:meth:`ClientSession.close() <aiohttp.ClientSession.close>` hanging indefinitely when using HTTPS requests through HTTP proxies -- by :user:`bdraco`. diff --git a/aiohttp/connector.py b/aiohttp/connector.py index 1c96ff42457..e1288424bff 100644
repro.py
import asyncio from aiohttp import ClientSession async def main(): proxy = "" session = ClientSession(proxy=proxy) async with session.get( "https://api.ipify.org/", ) as response: ip = await response.text() print("Closing session...") await session.close() print("Done") return ip asyncio.run(main())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Apply the official fix\nFixes a regression where ClientSession.close() would hang indefinitely when HTTPS requests were made through an HTTP proxy.\nWhen NOT to use: This fix should not be used if the application relies on the previous behavior of connection pooling.\n\n

Why This Fix Works in Production

  • Trigger: Regression when closing session
  • Mechanism: The regression was caused by CONNECT tunnel connections being pooled with proxy=None, leading to hanging futures
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.13.5 in real deployments (not just unit tests).
  • The regression was caused by CONNECT tunnel connections being pooled with proxy=None, leading to hanging futures
  • Production symptom (often without a traceback): Regression when closing session

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“So this only happens when the remote is ssl HTTP through proxy works fine, HTTPS through proxy: Creates a proxy=None connection (the CONNECT tunnel), session…”
@bdraco · 2025-07-09 · confirmation · source
“> Successfully installed aiohttp-3.12.13 > > > > import asyncio > from aiohttp import ClientSession > > async def main(): > proxy = "" >…”
@Nazar1ky · 2025-07-06 · confirmation · source
“I just saw the email show up. I'm traveling today and in flight. I'll look when I am on the ground and time adjusted”
@bdraco · 2025-07-08 · source
“We are going to try to do a release this week. I'm working on a PR”
@bdraco · 2025-07-09 · source

Failure Signature (Search String)

  • Regression when closing session
  • [V3.12.4](https://github.com/aio-libs/aiohttp/releases/tag/v3.12.4) Introduced a regression, in which, session with some proxies can't be closed.
Copy-friendly signature
signature.txt
Failure Signature ----------------- Regression when closing session [V3.12.4](https://github.com/aio-libs/aiohttp/releases/tag/v3.12.4) Introduced a regression, in which, session with some proxies can't be closed.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Regression when closing session [V3.12.4](https://github.com/aio-libs/aiohttp/releases/tag/v3.12.4) Introduced a regression, in which, session with some proxies can't be closed.

Minimal Reproduction

repro.py
import asyncio from aiohttp import ClientSession async def main(): proxy = "" session = ClientSession(proxy=proxy) async with session.get( "https://api.ipify.org/", ) as response: ip = await response.text() print("Closing session...") await session.close() print("Done") return ip asyncio.run(main())

Environment

  • Python: 3.13.5

What Broke

Closing the session hangs indefinitely when using HTTPS requests through HTTP proxies.

Why It Broke

The regression was caused by CONNECT tunnel connections being pooled with proxy=None, leading to hanging futures

Fix Options (Details)

Option A — Apply the official fix

Fixes a regression where ClientSession.close() would hang indefinitely when HTTPS requests were made through an HTTP proxy.

When NOT to use: This fix should not be used if the application relies on the previous behavior of connection pooling.

Fix reference: https://github.com/aio-libs/aiohttp/pull/11289

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the application relies on the previous behavior of connection pooling.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
  • Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.