-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
client: GET request continues after cancelling the task #3426
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #2286 (ClientSession.request unexpectedly cancels task on timeout), #1879 (Client: _request.timeout cancels the current AND the next request), #253 (Connection not closed when request is cancelled), #1861 (Client request timeout parameters are inconsistent), and #2755 (Client request tracing. Allow to get the request body in the trace.). |
Could you rework the example to use the single event loop in the main thread (with a couple of tasks maybe)? |
Here is an example with just one thread. The same result happens. I'm not sure why "a couple of tasks" (in other words, a more complex example) would be more illustrative than a minimal example.
Note that if I replace
Then the transfer truly stops (during the last 5 idle seconds of keeping the Python process alive), but this is simply a side effect of stopping the event loop. Replacing |
I am seeing this behavior as well under similar conditions, and am finding it rather problematic. Doing something to the order of: async with sess.get(url, timeout=30) as resp:
resp.raise_for_status()
if int(resp.headers['Content-Length']) >= 50<<20:
raise errors.BadArgument("File too big") The file continues to be downloaded in the background 8504117 does not seem to fix it |
Simple reproducer On windows, with aiohttp@master, and aiohttp 3.5.4, shows task continues to download (unmistakable, multiple Mbps...) even after exception raised import aiohttp
import asyncio
BIG_URL = "https://planet.openstreetmap.org/planet/full-history/history-latest.osm.bz2"
async def get_abort_file():
async with aiohttp.ClientSession() as sess:
async with sess.get(BIG_URL, timeout=30) as resp:
raise Exception("Raising exception immediately...")
loop = asyncio.get_event_loop()
async def amain():
try:
await get_abort_file()
except:
pass
await asyncio.sleep(999999)
loop.run_until_complete(amain()) Workaround I guess, if you have a This also seems to work, albeit a bit clunky. I don't see anywhere else this is exposed in 3.5.4 aiohttp.ClientSession(
connector=aiohttp.TCPConnector(enable_cleanup_closed=True)) |
Perhaps this deserves a separate issue, but I'll start here since it's the closest thing I could find in the issues page. I'm experiencing this while
|
#3426 (comment) |
Long story short
When I cancel a task which actually GETs a large file, I expect the transfer to truly stop once I called task.cancel().
Expected behaviour
CancelledError is raised inside my co-routine - the ClientSession context manager and request context manager is left, so I expect the request to have truly finished.
Actual behaviour
The transfer continues in the background.
Steps to reproduce
Output:
Your environment
Win10, Python 3.6.1, aiohttp 3.4.4
The text was updated successfully, but these errors were encountered: