Repository navigation
bpo-34638: Store a weak reference to stream reader to break strong references loop #9201
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c87303
Store a weak reference to stream readerfor breaking strong references
asvetlov 3ac4338
Work on
asvetlov 465d9b3
Make tests passing
asvetlov 5447b8a
Drop debug prints
asvetlov 521ec5d
Add NEWS entry
asvetlov a7b4ad1
Drop redundant assertion
asvetlov 806b5c2
_reject_transport -> _reject_connection
asvetlov 119bfab
Add a test for destroying a reader befor connection_made() call
asvetlov ced1bd2
Fix notes
asvetlov 1670250
Fix a comment
asvetlov 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
Fix notes
- Loading branch information
commit ced1bd2720c30f44c08678f52db11096ff324d92
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,9 +200,9 @@ def __init__(self, stream_reader, client_connected_cb=None, loop=None): | |
| else: | ||
| self._stream_reader_wr = None | ||
| if client_connected_cb is not None: | ||
| # server socket | ||
| # we need to keep a strong reference to the reader | ||
| # until connection is made | ||
| # This is a stream created by the `create_server()` function. | ||
| # Keep a strong reference to the reader until a connection | ||
| # is established. | ||
| self._strong_reader = stream_reader | ||
| self._reject_connection = False | ||
| self._stream_writer = None | ||
|
|
@@ -216,9 +216,8 @@ def _on_reader_gc(self, wr): | |
| if transport is not None: | ||
| # connection_made was called | ||
| context = { | ||
| 'message': ("Close transport. " | ||
| "A stream was destroyed without " | ||
| "stream.close() call") | ||
| 'message': ('An open stream object is being garbage ' | ||
| 'collected; call "stream.close()" explicitly.') | ||
| } | ||
| if self._source_traceback: | ||
| context['source_traceback'] = self._source_traceback | ||
|
|
@@ -240,9 +239,9 @@ def _stream_reader(self): | |
| def connection_made(self, transport): | ||
| if self._reject_connection: | ||
| context = { | ||
| 'message': ("Close transport. " | ||
| "a stream was destroyed " | ||
| "before connection establishment") | ||
| 'message': ('An open stream was garbage collected prior to ' | ||
| 'establishing network connection; ' | ||
| 'call "stream.close()" explicitly.') | ||
| } | ||
| if self._source_traceback: | ||
| context['source_traceback'] = self._source_traceback | ||
|
|
@@ -346,7 +345,7 @@ def can_write_eof(self): | |
| return self._transport.can_write_eof() | ||
|
|
||
| def close(self): | ||
| # a reader could be garbage collected / destroyed | ||
| # a reader can be garbage collected | ||
| # after connection closing | ||
|
Member
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. |
||
| self._protocol._untrack_reader() | ||
| return self._transport.close() | ||
|
|
||
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
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.
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.