Jump to solution
Verify

The Fix

Upgrade to version 0.7.2 or later.

Based on closed encode/httpx issue #922 · 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
@@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@ -import collections.abc import typing
repro.py
import asyncio import httpx proxies = {"http": "http://127.0.0.1:8080/"} async def request(): async with httpx.AsyncClient(proxies=proxies) as client: response = await client.get("http://example.org") assert response.status_code == 200 asyncio.run(request())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 0.7.2 or later.\nWhen NOT to use: This fix should not be applied if using a non-async environment.\n\n

Why This Fix Works in Production

  • Trigger: ✗ HTTPX_LOG_LEVEL=debug python .dev/bounded_semaphore_error.py
  • Mechanism: A BoundedSemaphore error occurs during the cleanup phase when using proxies with the async client
  • Why the fix works: Fixed a BoundedSemaphore error when using proxies with the async client in httpx. (first fixed release: 0.7.2).
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.8 in real deployments (not just unit tests).
  • A BoundedSemaphore error occurs during the cleanup phase when using proxies with the async client
  • Surfaces as: ✗ HTTPX_LOG_LEVEL=debug python .dev/bounded_semaphore_error.py

Proof / Evidence

  • GitHub issue: #922
  • Fix PR: https://github.com/encode/httpcore/pull/70
  • First fixed release: 0.7.2
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.42

Discussion

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

“I found the root cause in httpcore opening a PR there.”
@yeraydiazdiaz · 2020-05-02 · source

Failure Signature (Search String)

  • ✗ HTTPX_LOG_LEVEL=debug python .dev/bounded_semaphore_error.py

Error Message

Stack trace
error.txt
Error Message ------------- ✗ HTTPX_LOG_LEVEL=debug python .dev/bounded_semaphore_error.py DEBUG [2020-05-02 11:30:17] httpx._client - HTTP Request: GET http://example.org "HTTP/1.1 200 OK" Traceback (most recent call last): File ".dev/bounded_semaphore_error.py", line 13, in <module> asyncio.run(request()) File "/Users/yeray/.pyenv/versions/3.8.1/lib/python3.8/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/Users/yeray/.pyenv/versions/3.8.1/lib/python3.8/asyncio/base_events.py", line 612, in run_until_complete return future.result() File ".dev/bounded_semaphore_error.py", line 10, in request assert response.status_code == 200 File "/Users/yeray/code/personal/_forks/httpx/httpx/_client.py", line 1449, in __aexit__ await self.aclose() File "/Users/yeray/code/personal/_forks/httpx/httpx/_client.py", line 1438, in aclose await proxy.aclose() File "/Users/yeray/.pyenv/versions/httpcore/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 274, in aclose await self._remove_from_pool(connection) File "/Users/yeray/.pyenv/versions/httpcore/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 257, in _remove_from_pool self._connection_semaphore.release() File "/Users/yeray/.pyenv/versions/httpcore/lib/python3.8/site-packages/httpcore/_backends/asyncio.py", line 208, in release self.semaphore.rel ... (truncated) ...

Minimal Reproduction

repro.py
import asyncio import httpx proxies = {"http": "http://127.0.0.1:8080/"} async def request(): async with httpx.AsyncClient(proxies=proxies) as client: response = await client.get("http://example.org") assert response.status_code == 200 asyncio.run(request())

Environment

  • Python: 3.8

What Broke

Requests complete successfully, but an exception is raised during resource cleanup.

Why It Broke

A BoundedSemaphore error occurs during the cleanup phase when using proxies with the async client

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 0.7.2 or later.

When NOT to use: This fix should not be applied if using a non-async environment.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/encode/httpcore/pull/70

First fixed release: 0.7.2

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 applied if using a non-async environment.

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 CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.
  • 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.

Version Compatibility Table

VersionStatus
0.7.2 Fixed

Related Issues

No related fixes found.

Sources

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