[PR #6727/adeece3c backport][3.8] Fix asyncio.CancelledError again (#6719)#6741
Merged
Dreamsorcerer merged 1 commit into3.8from May 8, 2022
Conversation
* Fix asyncio.CancelledError again (#6719) `asyncio.CancelledError()` on peer disconnection have been removed by #4080, but #4415 re-introduced it silently. `self._waiter.cancel()` and `self._task_handler.cancel()` were added by #4415, but #4415 in fact only needed `self._waiter.cancel()` (proof below). So I propose to remove `self._task_handler.cancel()`, both #4080 and #4415 will be fixed. To test that I re-resolved #4080 I used: ```py async def handle(request): try: await asyncio.sleep(5) await request.text() except BaseException as e: print(f'base exception {type(e).__name__}') return web.Response(text='toto') ``` ```console curl -X POST -H "Content-Type: text/plain" --data "bouh" localhost:8080 ``` I kill the curl request before the 5 seconds of sleep. Before this PR I have the following error right after killing the curl: ```console $ python -Wall -X dev test.py ======== Running on http://0.0.0.0:8080 ======== (Press CTRL+C to quit) base exception CancelledError ``` After this commit I have the following error, but only after the 5 seconds sleep: ```console $ python -Wall -X dev test.py ======== Running on http://0.0.0.0:8080 ======== (Press CTRL+C to quit) base exception ConnectionResetError ``` To test that I didn't re-introduce #4415 I use a basic `handle` and 30 `curl localhost:8080`: - Before this commit no issue - If I remove `self._task_handler.cancel()` no issue - If I remove both `self._task_handler.cancel()` and `self._waiter.cancel()`: ```console $ python -Wall -X dev test.py ======== Running on http://0.0.0.0:8080 ======== (Press CTRL+C to quit) Task was destroyed but it is pending! task: <Task pending name='Task-4' coro=<RequestHandler.start() done, defined at ... Task was destroyed but it is pending! ... ``` So it's OK to remove only `self._task_handler.cancel()`. There is no documentation or tests to be updated because #4080 already did that part. However I guess that for a few people it might be seen as a breaking change, I'm not sure. Tested on master and on v3.8.1. fixes #6719 * Update 6719.bugfix Co-authored-by: Sam Bull <[email protected]> (cherry picked from commit adeece3)
Contributor
|
@Dreamsorcerer Thanks for the review and merge! A release of aiohttp v3.8.2 with this change would be useful for me in production, do you have an expected release date for aiohttp v3.8.2? |
Member
|
I've never done a release for aiohttp before, so I'm hoping someone else will come back to it. If they're still away in a while, then I'll try and figure out a 3.8 release. |
Contributor
|
Hi @Dreamsorcerer! It's been a month since the merge of this PR, maybe a new release could be considered? (Sorry to bother you with that, thanks again for your help on the subject) |
Contributor
|
Hi, @Dreamsorcerer @asvetlov! Sorry to bother you, but can you tell me if there is still no new released planned in the coming weeks? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #6727 as merged into master (adeece3).
asyncio.CancelledError()on peer disconnection have been removed by #4080,but #4415 re-introduced it silently.
self._waiter.cancel()andself._task_handler.cancel()were added by #4415,but #4415 in fact only needed
self._waiter.cancel()(proof below).So I propose to remove
self._task_handler.cancel(), both #4080 and #4415 willbe fixed.
To test that I re-resolved #4080 I used:
curl -X POST -H "Content-Type: text/plain" --data "bouh" localhost:8080I kill the curl request before the 5 seconds of sleep.
Before this PR I have the following error right after killing the curl:
After this commit I have the following error, but only after the 5 seconds
sleep:
To test that I didn't re-introduce #4415 I use a basic
handleand 30curl localhost:8080:Before this commit no issue
If I remove
self._task_handler.cancel()no issueIf I remove both
self._task_handler.cancel()andself._waiter.cancel():So it's OK to remove only
self._task_handler.cancel().There is no documentation or tests to be updated because #4080 already did that
part.
However I guess that for a few people it might be seen as a breaking change,
I'm not sure.
Tested on master and on v3.8.1.
fixes #6719