Suggesting aiohttp.ClientSession.abort()
- Dominant language
- Python
- Stars
- 16.5k
- Forks
- 2.4k
- Avg merge
- 17h 22m
- Merged PRs (30d)
- 212
Description
## Long story short
I'm making a web crawler for video contents.
My program checks the content-length field,
and skip downloading if content-length is equal to the local content.
However, resp.close() does not close the connection
when the connection is using HTTPS.
SSLProtocol._start_shutdown() is too graceful so that
the connection is working background to download all the video content.
(chunked encoding is not a solution because some servers do not support them)
This causes my system to have "too many file descriptors in select" error
even though I'm closing connections by "resp.close()".
asyncio.transports.Transport has a nice abstraction "abort()"
which does exactly what I want to do.
However, none of the aiohttp.TCPConnector, aiohttp.ClientSession,
aiohttp.ClientResponse invokes the "abort()".
Considering keep-alive connections, killing connection from a "response" is not clear.
My suggestion is to make "abort()" API to the aiohttp.ClientSession.abort().
(We already have close() in aiohttp.ClientSession and aiohttp.ClientResponse).
Here is my current hack, but I hope that this feature would be possible
without using private field starting with "_".
``` .py
conn = session.connector
if hasattr(conn, "_acquired"):
for transport in itertools.chain(*conn._acquired.values()):
if isinstance(transport, asyncio.transports.Transport):
transport.abort()
```
Contributor guide
Assessment
This issue has not been assessed yet.