GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times by Fidget-Spinner · Pull Request #98704 · python/cpython

Conversation

@Fidget-Spinner

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Consistent test failures in test test_asyncio.test_streams.test_drain_raises on Windows #98703

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fidget-Spinner
Fix asyncio proactor_events calling _call_connection_lost multiple times
f348542
@Fidget-Spinner
Fidget-Spinner requested review from 1st1, asvetlov and gvanrossum as code owners October 26, 2022 07:50
@bedevere-bot bedevere-bot added the awaiting core review label Oct 26, 2022
@Fidget-Spinner
Fidget-Spinner requested a review from kumaraditya303 October 26, 2022 07:50
@blurb-it
📜🤖 Added by blurb_it.
5a3211e
@Fidget-Spinner

Fidget-Spinner commented Oct 26, 2022

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner Fidget-Spinner added needs backport to 3.10 needs backport to 3.11 only security fixes release-blocker and removed release-blocker labels Oct 26, 2022
@kumaraditya303

kumaraditya303 commented Oct 26, 2022

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Oct 26, 2022
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner @kumaraditya303
Apply suggestions by Kumar
26dfd85
Co-Authored-By: Kumar Aditya <[email protected]>
@Fidget-Spinner

Fidget-Spinner commented Oct 26, 2022

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Oct 26, 2022
View reviewed changes
Comment thread Lib/asyncio/proactor_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Oct 26, 2022
View reviewed changes
Comment thread Lib/asyncio/proactor_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner @kumaraditya303
Apply suggestions again
9a4b6f8
Co-Authored-By: Kumar Aditya <[email protected]>
kumaraditya303
kumaraditya303 approved these changes Oct 26, 2022
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM thanks for the PR!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kumaraditya303 kumaraditya303 added the topic-asyncio label Oct 26, 2022
This was referenced Oct 26, 2022
gh-98713: Use @cpython_only for a test that fails on PyPy #98714
Merged
gh-98586: Add vector call APIs to the Limited API #98587
Merged
@kumaraditya303

kumaraditya303 commented Oct 26, 2022

Copy link
Copy Markdown
Contributor

I created #98730 to add tests for this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner Fidget-Spinner mentioned this pull request Oct 26, 2022
gh-98703: add tests for closing _ProactorSocketTransport with proactor event loop #98730
Merged
gvanrossum
gvanrossum approved these changes Oct 27, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

Ironic.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Oct 27, 2022
@Fidget-Spinner
Fidget-Spinner merged commit 8a75542 into python:main Oct 27, 2022
@miss-islington

miss-islington commented Oct 27, 2022

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Oct 27, 2022
@Fidget-Spinner
Fidget-Spinner deleted the fix_asyncio_test_drain_release branch October 27, 2022 02:37
@miss-islington

miss-islington commented Oct 27, 2022

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington miss-islington assigned Fidget-Spinner Oct 27, 2022
@bedevere-bot

bedevere-bot commented Oct 27, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 27, 2022
@Fidget-Spinner @miss-islington
pythongh-98703: Fix asyncio proactor_events calling _call_connection_…
a4da65b
…lost multiple times (pythonGH-98704)

Co-authored-by: Kumar Aditya <[email protected]>
(cherry picked from commit 8a75542)

Co-authored-by: Ken Jin <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 label Oct 27, 2022
@Fidget-Spinner 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
@miss-islington

miss-islington commented 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.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Oct 27, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot 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
@Fidget-Spinner @miss-islington
pythongh-98703: Fix asyncio proactor_events calling _call_connection_…
2a54ef6
…lost multiple times (pythonGH-98704)

Co-authored-by: Kumar Aditya <[email protected]>
(cherry picked from commit 8a75542)

Co-authored-by: Ken Jin <[email protected]>
miss-islington added a commit that referenced this pull request Oct 27, 2022
@miss-islington @Fidget-Spinner
gh-98703: Fix asyncio proactor_events calling _call_connection_lost m…
bb80f6a
…ultiple times (GH-98704)

Co-authored-by: Kumar Aditya <[email protected]>
(cherry picked from commit 8a75542)

Co-authored-by: Ken Jin <[email protected]>
miss-islington added a commit that referenced this pull request Oct 27, 2022
@miss-islington @Fidget-Spinner
gh-98703: Fix asyncio proactor_events calling _call_connection_lost m…
08ce791
…ultiple times (GH-98704)

Co-authored-by: Kumar Aditya <[email protected]>
(cherry picked from commit 8a75542)

Co-authored-by: Ken Jin <[email protected]>
gvanrossum pushed a commit to gvanrossum/cpython that referenced this pull request Oct 28, 2022
@Fidget-Spinner @kumaraditya303 @gvanrossum
pythongh-98703: Fix asyncio proactor_events calling _call_connection_…
f8d9bb5
…lost multiple times (pythonGH-98704)

Co-authored-by: Kumar Aditya <[email protected]>
@mxschmitt mxschmitt mentioned this pull request May 4, 2026
asyncio: _ProactorBasePipeTransport._call_connection_lost leaks OSError [WinError 6] from PipeHandle.close() on Windows #149388
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum gvanrossum approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Fidget-Spinner Fidget-Spinner

Labels

topic-asyncio

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@Fidget-Spinner @kumaraditya303 @miss-islington @bedevere-bot @gvanrossum
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.