Jump to solution
Verify

The Fix

Upgrade to version 0.13.0 or later.

Based on closed encode/httpx issue #824 · 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
@@ -862,6 +862,8 @@ def delete( def close(self) -> None: self.dispatch.close() + for proxy in self.proxies.values(): + proxy.close()
repro.py
import os,httpx,asyncio async def main(): proxies_list=[ {'all':'http://4.3.2.1:8080'}, {'all':'http://1.2.3.4:8080'}, ] for i in range(10): proxies=proxies_list[i%2] async with httpx.AsyncClient(proxies=proxies) as client: r=await client.get('http://my-url.com/') print('lsof -np',os.getpid()) for i in range(60): print(i) await asyncio.sleep(3) asyncio.run(main())
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.13.0 or later.\nWhen NOT to use: This fix should not be applied if the application requires persistent proxy connections.\n\n

Why This Fix Works in Production

  • Trigger: Too many open files if keep changing proxy
  • Mechanism: Proxy dispatch classes were not being closed properly, leading to too many open files
  • Why the fix works: Closes the issue by ensuring that proxy dispatch classes are closed when the Client is closed, preventing too many open files errors. (first fixed release: 0.13.0).
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

  • Proxy dispatch classes were not being closed properly, leading to too many open files
  • Surfaces as: Too many open files if keep changing proxy

Proof / Evidence

  • GitHub issue: #824
  • Fix PR: https://github.com/encode/httpx/pull/826
  • First fixed release: 0.13.0
  • 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.66

Discussion

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

“Good observation..”
@lovelydinosaur · 2020-02-25 · confirmation · source
“> Good observation... Actually, I am writing a web crawler, after runing 1-2 days it crashes because of "too many open files", this is how…”
@Jonney · 2020-02-25 · source

Failure Signature (Search String)

  • Too many open files if keep changing proxy

Error Message

Stack trace
error.txt
Error Message ------------- Too many open files if keep changing proxy

Minimal Reproduction

repro.py
import os,httpx,asyncio async def main(): proxies_list=[ {'all':'http://4.3.2.1:8080'}, {'all':'http://1.2.3.4:8080'}, ] for i in range(10): proxies=proxies_list[i%2] async with httpx.AsyncClient(proxies=proxies) as client: r=await client.get('http://my-url.com/') print('lsof -np',os.getpid()) for i in range(60): print(i) await asyncio.sleep(3) asyncio.run(main())

What Broke

Frequent proxy changes resulted in 'too many open files' errors during execution.

Why It Broke

Proxy dispatch classes were not being closed properly, leading to too many open files

Fix Options (Details)

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

Upgrade to version 0.13.0 or later.

When NOT to use: This fix should not be applied if the application requires persistent proxy connections.

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

Fix reference: https://github.com/encode/httpx/pull/826

First fixed release: 0.13.0

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 the application requires persistent proxy connections.

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.
  • Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
  • Add a long-running test that repeats the failing call path and asserts stable memory.

Version Compatibility Table

VersionStatus
0.13.0 Fixed

Related Issues

No related fixes found.

Sources

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