Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
bpo-42130: Fix swallowing of cancellation by wait_for#26097
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1147,22 +1147,6 @@ def gen(): | ||
| res = loop.run_until_complete(task) | ||
| self.assertEqual(res, "ok") | ||
| def test_wait_for_cancellation_race_condition(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test now fail if it wasn't removed? Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. The test is incorrect (the task must raise) and it doesn't reproduce original problem. | ||
| def gen(): | ||
| yield 0.1 | ||
| yield 0.1 | ||
| yield 0.1 | ||
| yield 0.1 | ||
| loop = self.new_test_loop(gen) | ||
| fut = self.new_future(loop) | ||
| loop.call_later(0.1, fut.set_result, "ok") | ||
| task = loop.create_task(asyncio.wait_for(fut, timeout=1)) | ||
| loop.call_later(0.1, task.cancel) | ||
| res = loop.run_until_complete(task) | ||
| self.assertEqual(res, "ok") | ||
| def test_wait_for_waits_for_task_cancellation(self): | ||
| loop = asyncio.new_event_loop() | ||
| self.addCleanup(loop.close) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :meth:`asyncio.wait_for` fix swallowing of cancellation |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the state
wait_foris in right now (outside this PR) is as bad asin swallowing a
KeyboardInterruptin a utility function. It makes it unusablein my opinion. There is also no way for user code to counteract, whereas the
resource leakage could actually be worked around.
This leads me to possibility 1 how I think this issue could be solved:
Merge this PR, embrace the quirk and document it well.
Tell the user something along the lines of
Or alternatively:
After all, if the wrapped future yields multiple times to the event loop, you don't get any guarantees as to how far your inner future got. So the user has to be prepared to clean-up the cancellation mess one or the other way.
Possibility 2 I see is to not dismiss, but to defer the cancellation:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To amend to that: this is the issue that I thinks needs a quick resolution (using pytest here, but it should get the point across):