-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-46309: Added reference to task created by StreamReaderProtocol #30505
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62cdd31
Added reference to task created by StreamReaderProtocol
simwr872 11cc789
Apply suggestions from code review
simwr872 d1586c5
Merge branch 'main' into fix-issue-46309
gvanrossum 2a27d0c
Remove test and use single task reference instead of set
2024570
Merge branch 'python:main' into fix-issue-46309
simwr872 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2022-01-09-17-57-53.bpo-46309.BaLgD1.rst
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added reference to task created in | ||
:meth:`asyncio.streams.StreamReaderProtocol.connection_made`. |
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 comment was marked as resolved.
Sorry, something went wrong.
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.
Thanks for looking at the changes! I signed the CLA ~3 hours before this PR, so hopefully it will be OK'd sometime today. Your requested changes makes sense. However from my testing, creating the future outside of the callback will not allow the task to be garbage collected. That is, the test will pass even without keeping a reference to the task in
StreamReaderProtocol
.One solution could be to still create the future inside the callback, but cancel the task via the newly created reference in
StreamReaderProtocol
. Perhaps you have a better suggestion. I can spend some more time on this later today.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.
You are completely correct. I've spent quite a few hours triaging the source of the original issue on stackoverflow and realized the bug is caused when the garbage collector breaks a cyclic reference between the writer, the reader, the task and a future created inside the reader. If any of them are referenced outside of the function, the bug will not appear.
I don't suggest accessing the internals from the test. You're welcome to decline my changes in the tests as long as asyncio doesn't throw any warning about the leak. The garbage collector will take care of it when the loop is closed, or it will be cancelled accordingly.
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've accepted your suggested changes in
streams.py
. As for the leaking test callback, a different solution could be to useasyncio.all_tasks(self.loop).pop().cancel()
right after the assertion.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 believe it's unnecessary - It will cause more confusion, and will get bugged if the internals will change and a new task will be created in the background.
I think we're better off letting the cleanup take care of it.