_RequestContextManager
being awaitable is dangerous
#8227
RunDevelopment
started this conversation in
General
Replies: 1 comment 2 replies
-
The implementation of that has always looked rather awkward to me, but the design is deliberate. While we generally recommend the context manager, there are many examples in the docs that do it this way. The connection should be released after a read(): https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientResponse.read So, what specifically is leaking? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've recently debugged a case where a
ClientSession
always timeouted even if the server being connected to was still alive. I found that the cause of this issue was improper usage of a_RequestContextManager
. The offending code looked something like this:This code is simple to write, looks correct, works, and silently leaks resources. We use ruff and pyright in our code base and both tools were unable to find this mistake.
I think that the fact that
await session.get("/path")
works is an oversight in the API design of_RequestContextManager
. This makes it too simple to leak resources without any tools being able to help.Instead of
_RequestContextManager
itself being awaitable, I would suggest a property that gives access to the underlying coroutine (or a wrapper around it).Beta Was this translation helpful? Give feedback.
All reactions