-
-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceWarning: unclosed transport <_SelectorSocketTransport fd=6> (asyncio only) #825
Comments
Tried with
|
So this is related to #634, _backends/asyncio.py, SocketStream's close method:
Obviously adding a So I'm going to read #634 now. |
Hi @JulienPalard, This is very strange to me. It's a straight-on request/response flow, no redirects, no special cases that surface in the TRACE logs… Also, I am not able to reproduce on Python 3.8.1/HTTPX 0.11.1. |
Huhh… I'm sick with issues we've been having with asyncio's You can also look at the end of #714. Our conclusion back then was to close off as "this is a Python bug". @tomchristie also noted:
which matches my experience on 3.8.1. The bug may have come back on 3.8.2…? 🤷♂ |
@JulienPalard I'm curious — what happens if you import asyncio
import httpx
async def mdk():
async with httpx.AsyncClient() as client:
r = await client.get('https://www.example.org/')
print(r.text)
await asyncio.sleep(0) # <--
asyncio.run(mdk()) |
Feasible that it could be a duplicate of #824 if there happens to be proxies setup in the environment. Few questions here @JulienPalard:
|
@florimondmanca No, adding |
Checks done using httpx on current HEAD (50d337e), ipython==7.12.0, on Debian bullseye, trio==0.13.0: Sorry I don't know how to design 3d tables in markdown. So, Python 3.8.2
Python 3.8.1
Python 3.8.0
[1]: import asyncio # or import trio
import httpx
async def mdk():
async with httpx.AsyncClient(trust_env=False) as client:
r = await client.get('https://www.example.org/')
print(r.text)
asyncio.run(mdk()) # or trio.run(mdk) |
I'm changing the title appropriately, as the "An open stream ..." has been fixed in Python 3.8.1, this discussion is about the ResourceWarning. |
Gotcha, thanks @JulienPalard. We'd be able to resolve that if we were doing what we're supposed to and calling I guess things we ought to figure out are:
|
Also worth investigating - how are the |
Here's a minimal reproducing case... import asyncio
import ssl
import certifi
hostname = 'login.microsoftonline.com'
context = ssl.create_default_context()
context.load_verify_locations(cafile=certifi.where())
async def main():
reader, writer = await asyncio.open_connection(hostname, 443, ssl=context)
print('opened')
writer.close()
print('close started')
await writer.wait_closed()
print('close completed')
asyncio.run(main()) |
Haven't looked into how awkward it is to do, but really I think we'd want to monkeypatch asyncio's socket unwrapping behaviour, so that we can reliably call |
Okay, so reviewed this one today, and looks like we can close it off. Our asyncio backend has this comment... # NOTE: StreamWriter instances expose a '.wait_closed()' coroutine function,
# but using it has caused compatibility issues with certain sites in
# the past (see https://github.com/encode/httpx/issues/634), which is
# why we don't call it here.
# This is fine, though, because '.aclose()' schedules the actual closing of the
# stream, meaning that at best it will happen during the next event loop
# iteration, and at worst asyncio will take care of it on program exit.
async with self.write_lock:
with map_exceptions({OSError: CloseError}):
self.stream_writer.close() Also, this does not reproduce any warnings... import httpx
import asyncio
async def main():
async with httpx.AsyncClient() as client:
r = await client.get("https://login.microsoftonline.com/")
print(r)
asyncio.run(main(), debug=True) |
Oh right, I think we'll need to look into a fix that allows us to call |
References: #550
On 0.11.1 and current HEAD 50d337e I'm getting:
The text was updated successfully, but these errors were encountered: