You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
connection leaking in some network condition #1360
httpcore_async\http_proxy.py line206 - line244
If any exception(like ReadTimeout) raise between socket establishing and adding connection to pool, connection will leak.
I set read timeout to 1s, connect timeout to 15s.
code here:
import os
os.environ["HTTPX_LOG_LEVEL"] = "TRACE"
import asyncio
import httpx
from httpx._config import Timeout
async def run():
try:
async with httpx.AsyncClient(proxies="some proxy address") as client:
r = await client.get('https://www.baidu.com/', timeout=Timeout(5, connect=15, read=1))
await asyncio.sleep(40)
rasie
except Exception as exc:
print(type(exc))
await asyncio.sleep(40)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
log here:
after AsyncClient is closed, socket is still there.
conclusion:
Even if AsyncClient.aexit has executed, but socket remain ESTABLISHED, because exception raise before calling
AsyncConnectionPool._add_to_pool, AsyncConnectionPool._connections is empty.
Activity
cdeler commentedon Oct 14, 2020
Hello @everAwayne ,
Yes, it's probably a bug in
httpcore.I wrote a test case to make it reproducible. In the test case we try to access the domain, which is in our proxy blacklist.
To make the test case effective we need to run
pproxywith a "blocked domains" list: