Jump to solution
Verify

The Fix

Introduced a new Client.stream() method to ensure proper context management for streaming requests, addressing the issue of unclosed connections.

Based on closed encode/httpx issue #588 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -10,11 +10,10 @@ Pretty much any API mentioned in the `requests` QuickStart should be identical * `Response.url` - Returns a `URL` instance, rather than a string. Use `str(response.url)` if you need a string instance. -* `httpx.codes` - In our documentation we prefer the uppercased versions, such as `codes.NOT_FOUND`, -but also provide lower-cased versions for API compatibility with `requests`. -* `stream=True`. - Streaming responses provide the `.stream()` and `.raw()` byte iterator interfaces, rather than the `.iter_content()` method and the `.raw` socket interface.
repro.py
async with client.stream(url) as response: # Defaults to GET ... async with client.stream("POST", url) as response: ...
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\nIntroduced a new Client.stream() method to ensure proper context management for streaming requests, addressing the issue of unclosed connections.\nWhen NOT to use: Do not use this fix if backward compatibility with existing streaming methods is required.\n\n

Why This Fix Works in Production

  • Trigger: For the 1.0 release I think we should consider? droping `stream=True`, as it makes it *exceptionally* easy to leave unclosed connections hanging around.
  • Mechanism: The streaming API allowed unclosed connections due to improper context management

Why This Breaks in Prod

  • The streaming API allowed unclosed connections due to improper context management
  • Production symptom (often without a traceback): For the 1.0 release I think we should consider? droping `stream=True`, as it makes it *exceptionally* easy to leave unclosed connections hanging around.

Proof / Evidence

Discussion

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

“> Explicit request methods, for the streaming case... That’s the most reasonable option, IMO.”
@florimondmanca · 2019-12-04 · source
“> There's one other bit of API that would need finessing in order to achieve that, which would be to drop the one other bit…”
@florimondmanca · 2019-12-05 · source
“> AsyncResponse *Or*..”
@florimondmanca · 2019-12-05 · source
“> Thinking about alternatives, the fact that we have "one method per HTTP verb" for the non-streaming case and "one method accepting the HTTP verb"…”
@lovelydinosaur · 2019-12-04 · source

Failure Signature (Search String)

  • For the 1.0 release I think we should consider? droping `stream=True`, as it makes it *exceptionally* easy to leave unclosed connections hanging around.
  • That way users never have to think about "did I call close on the response", or leave open connections hanging around accidentally.
Copy-friendly signature
signature.txt
Failure Signature ----------------- For the 1.0 release I think we should consider? droping `stream=True`, as it makes it *exceptionally* easy to leave unclosed connections hanging around. That way users never have to think about "did I call close on the response", or leave open connections hanging around accidentally.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- For the 1.0 release I think we should consider? droping `stream=True`, as it makes it *exceptionally* easy to leave unclosed connections hanging around. That way users never have to think about "did I call close on the response", or leave open connections hanging around accidentally.

Minimal Reproduction

repro.py
async with client.stream(url) as response: # Defaults to GET ... async with client.stream("POST", url) as response: ...

What Broke

Users experienced unclosed connections leading to resource leaks and potential timeouts.

Why It Broke

The streaming API allowed unclosed connections due to improper context management

Fix Options (Details)

Option A — Apply the official fix

Introduced a new Client.stream() method to ensure proper context management for streaming requests, addressing the issue of unclosed connections.

When NOT to use: Do not use this fix if backward compatibility with existing streaming methods is required.

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

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if backward compatibility with existing streaming methods is required.

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.

Related Issues

No related fixes found.

Sources

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