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
@@ -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.
async with client.stream(url) as response: # Defaults to GET
...
async with client.stream("POST", url) as response:
...
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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
- GitHub issue: #588
- Fix PR: https://github.com/encode/httpx/pull/600
- Reproduced locally: No (not executed)
- Last verified: 2026-02-12
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.58
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.”
“> 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…”
“> AsyncResponse *Or*..”
“> 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"…”
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
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 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
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.
Fix reference: https://github.com/encode/httpx/pull/600
Last verified: 2026-02-12. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if backward compatibility with existing streaming methods is required.
Verify Fix
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.