8000 bpo-37658: Actually return result in race condition by Dreamsorcerer · Pull Request #29202 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37658: Actually return result in race condition #29202

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

Merged
merged 6 commits into from
Nov 29, 2021

Conversation

Dreamsorcerer
Copy link
Contributor
@Dreamsorcerer Dreamsorcerer commented Oct 24, 2021

Splitting this out from #28149 to ease review.

The original test written for this issue is bogus and fails to reproduce the bug report. I've replaced it with a test that reproduces the error, and have actually fixed the problem reported.

https://bugs.python.org/issue37658

@Dreamsorcerer Dreamsorcerer changed the title bpo-37658: Actually fix the problem bpo-37658: Actually return result in race condition Oct 24, 2021
@@ -1101,24 +1096,6 @@ async def inner():
with self.assertRaises(FooException):
loop.run_until_complete(foo())

def test_wait_for_raises_timeout_error_if_returned_during_cancellation(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test literally tests that we don't return a value when it has completed successfully...

I can't see any reason for this test, the issue linked to the PR does not mention anything that warrants this test existing: https://bugs.python.org/issue40607

So, as far as I can tell, this test should be binned and the behaviour should be as defined in the above changes.

yield 0.1
yield 0.1
async def inner():
with contextlib.suppress(asyncio.CancelledError):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I just emulated the race condition in the bug report, but because it's a race condition, it seems that the test occasionally failed due to actually hitting the timeout.

Instead, I've just suppressed the cancellation, which makes the behaviour 100% reproducible.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an equivalent test. As I understand, the whole point of that test was to inject the cancellation at the exact point to cause the race on the return to ‘await waiter’ once fut is done. The new test is not checking this race at all but instead checking that a cancellation ignoring task can skip the timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an equivalent test, because the previous test is completely wrong. It does not emulate a race condition, and it does not reproduce the issue in the bug report.

I wrote a test which actually reproduces the race condition as given in the bug report, and the issue was not fixed. As mentioned above, I had to use this suppress cancellation trick to make the test reproducible (it will still run things in the same order as the race condition), the original test worked correctly everytime I ran it, but failed in one of the CI runs, and we can't have flaky tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see the old version which was timing dependent in the commit history:
169294e

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Nov 25, 2021
Copy link
Contributor
@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is correct.

Please add a NEWS entry.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@Dreamsorcerer
Copy link
Contributor Author

I couldn't run the blurb add command that seemed to be suggested, but I think that's right.

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Nov 29, 2021
@asvetlov
Copy link
Contributor

Thanks!

@asvetlov asvetlov merged commit 934a826 into python:main Nov 29, 2021
@miss-islington
Copy link
Contributor

Thanks @Dreamsorcerer for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Nov 29, 2021
@bedevere-bot
Copy link

GH-29832 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 29, 2021
(cherry picked from commit 934a826)

Co-authored-by: Sam Bull <aa6bs0@sambull.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 29, 2021
(cherry picked from commit 934a826)

Co-authored-by: Sam Bull <aa6bs0@sambull.org>
@bedevere-bot
Copy link

GH-29831 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 29, 2021
miss-islington added a commit that referenced this pull request Nov 29, 2021
(cherry picked from commit 934a826)

Co-authored-by: Sam Bull <aa6bs0@sambull.org>
asvetlov pushed a commit that referenced this pull request Nov 30, 2021
)

(cherry picked from commit 934a826)

Co-authored-by: Sam Bull <aa6bs0@sambull.org>

Co-authored-by: Sam Bull <aa6bs0@sambull.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0