Closed JulienPalard closed 4 years ago
This appears resolved in 0.8 to me. Our redirect middleware wasn't closing the redirect response, which we are now doing.
Still an issue on Ubuntu 18.04.5, python 3.8.0 and httpx 0.16.1
import asyncio
import httpx
async def test():
async with httpx.AsyncClient() as client:
resp = await client.get('https://httpbin.org/get')
asyncio.run(test())
An open stream object is being garbage collected; call "stream.close()" explicitly.
Currently, using cpython 3.8 and httpx and HEAD (a05ba2e9148c3f74c80c68a727b7e52b3d751c8c), with this script:
I'm getting:
It looks like two connections are created, the second one during the redirection to
/fr/3.8/
.Tried with
HTTPX_LOG_LEVEL=trace
:Looks like the first connection is not released, so it's probably near the redirect code, maybe closing the connection right before loosing the reference to the response may be the fix, but it feels "a bit wrong" to have to care about this in such a remote place, and it feels really wrong to have to close the connection to release it to the pool, it's a keepalive connection it should be kept open and reused.
FYI if I apply the patch I see:
Any hint on how to do it more cleanly?
What about an asynchronous context manager to take connection from the pool instead of passing a callback to the release method?