Closed psclafer closed 5 years ago
Thanks for the patch!
Looking at the commit messages:
uaiohttp: Add aclose() method to ClientResponse
While patch actually patches uaiohttpclient.py. What goes into prefix:
, should be exact module name (uaiohttpclient), to avoid any confusion.
Speaking of that, how the original uaiohttp deals with that?
Otherwise, I agree with the nature of the patches and argumentation. Similar issues were already handled in other HTTP module(s), e.g. 586ae64cb0f2afa7ef26aec360cb8b09948fd8f5 . But the actual way to do that may require further consideration, will review in more detail when get a chance.
Speaking of that, how the original uaiohttp deals with that?
The original aiohttp ClientResponse has a close() method. But this can be handled using a context manager.
Example taken from the aiohttp documentation:
async with aiohttp.ClientSession() as session:
async with session.get('http://httpbin.org/get') as resp:
print(resp.status)
print(await resp.text())
Thanks for the report, uaiohttpclient.ClientResponse.aclose() method was added (from scratch, to be sure of the correctness of implementation).
There is no method to close the Reponse. This leads to a memory leak by filling uasyncio select pool and preventing the GC to clean the sockets and related uasyncio data: Example:
Adding the method aclose() in ClientReponse resolve the issue. (Commit 049c79e)
But, in case of an exceptions during request handling, uaiohttp has a serious issue. A typical example is the usage of wait_for with a slow HTTP server. Here the server is tuned to take 1.0s between -accepting the connection/receiving the request- and -send back the first http header.
In that case, the poller wakes up uasyncio for a canceled request while the next request or the next sleep has been started. uasyncio becomes unstable with an unpredictable behavior leading to a crash of the loop. This use case is absolutely necessary for production systems. The second commit (2a5c8cc) handle theses cases by closing the reader and the socket when an exception occurs during processing.
I'm not sure that theses patchs are prefect, but I think it's a big improvement for this module, to be used for real.
`