← 返回首页
gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times by Fidget-Spinner · Pull Request #98704 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times#98704

Merged
Fidget-Spinner merged 4 commits into
python:mainfrom
Fidget-Spinner:fix_asyncio_test_drain_release
Oct 27, 2022
Merged

gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times#98704
Fidget-Spinner merged 4 commits into
python:mainfrom
Fidget-Spinner:fix_asyncio_test_drain_release

Conversation

Fidget-Spinner commented Oct 26, 2022
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

@kumaraditya303 I don't know why but this started showing on our tests after #98572. I can't tell if that PR introduced a bug or it just exposed something wrong with our implementation.

IMO, it seems it's something wrong with our implementation.

Copy link
Copy Markdown
Contributor

asyncio always has surprises hence it is my favorite :)

Seriously though this has uncovered another race in our implementation. The code does not guard against concurrent closing of the stream which leads to this failure. The connection_lost callback should be called only once and here it is being called more than once.

Here's a better fix:

diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 2685a3376c..c6aab408fc 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -152,6 +152,8 @@ def _force_close(self, exc): self._loop.call_soon(self._call_connection_lost, exc) def _call_connection_lost(self, exc): + if self._called_connection_lost: + return try: self._protocol.connection_lost(exc) finally:

Feel free to update this PR with the patch above, I have verified this.

Comment thread Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst Outdated Show resolved Hide resolved
Co-Authored-By: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>

Copy link
Copy Markdown
Member Author

Feel free to update this PR with the patch above, I have verified this.

Awesome! Thank you for the fix. I was trying to find something more elegant but I'm a noob at asyncio internals :). Your fix is way nicer.

Comment thread Lib/asyncio/proactor_events.py Show resolved Hide resolved
Comment thread Lib/asyncio/proactor_events.py Show resolved Hide resolved
Co-Authored-By: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>

kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

LGTM thanks for the PR!

Copy link
Copy Markdown
Contributor

I created #98730 to add tests for this.

gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Ironic.

Copy link
Copy Markdown
Contributor

Thanks @Fidget-Spinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

Fidget-Spinner deleted the fix_asyncio_test_drain_release branch October 27, 2022 02:37

Copy link
Copy Markdown
Contributor

Sorry @Fidget-Spinner, I had trouble checking out the 3.11 backport branch.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Alternatively, you can backport using cherry_picker on the command line.
cherry_picker 8a755423eba8e19704d96905730cf7f50083eb23 3.11

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 27, 2022
…lost multiple times (pythonGH-98704) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> (cherry picked from commit 8a75542) Co-authored-by: Ken Jin <kenjin@python.org>
bedevere-bot removed the needs backport to 3.10 only security fixes label Oct 27, 2022
Fidget-Spinner added needs backport to 3.11 only security fixes and removed needs backport to 3.11 only security fixes labels Oct 27, 2022

Copy link
Copy Markdown
Contributor

Thanks @Fidget-Spinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

Copy link
Copy Markdown

GH-98754 is a backport of this pull request to the 3.11 branch.

bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 27, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 27, 2022
…lost multiple times (pythonGH-98704) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> (cherry picked from commit 8a75542) Co-authored-by: Ken Jin <kenjin@python.org>
miss-islington added a commit that referenced this pull request Oct 27, 2022
…ultiple times (GH-98704) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> (cherry picked from commit 8a75542) Co-authored-by: Ken Jin <kenjin@python.org>
miss-islington added a commit that referenced this pull request Oct 27, 2022
…ultiple times (GH-98704) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> (cherry picked from commit 8a75542) Co-authored-by: Ken Jin <kenjin@python.org>
gvanrossum pushed a commit to gvanrossum/cpython that referenced this pull request Oct 28, 2022
…lost multiple times (pythonGH-98704) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Footer

© 2026 GitHub, Inc.