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
Make tests passing
- Loading branch information
commit 465d9b3e217ae2bcfb65f3baf9a34b9b8204ac8b
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 |
|---|---|---|
|
|
@@ -221,7 +221,9 @@ def _on_reader_gc(self, wr): | |
| # connection_made was called | ||
| print("schedule abort") | ||
| context = { | ||
| 'message': "Stream was garbage collected" | ||
| 'message': ("Close transport. " | ||
| "A stream was destroyed without " | ||
| "stream.close() call") | ||
| } | ||
| if self._source_traceback: | ||
| context['source_traceback'] = self._source_traceback | ||
|
|
@@ -231,6 +233,9 @@ def _on_reader_gc(self, wr): | |
| self._reject_transport = True | ||
| self._stream_reader_wr = None | ||
|
|
||
| def _untrack_reader(self): | ||
| self._stream_reader_wr = None | ||
|
|
||
| @property | ||
| def _stream_reader(self): | ||
| if self._stream_reader_wr is None: | ||
|
|
@@ -241,7 +246,9 @@ def connection_made(self, transport): | |
| print("connection made") | ||
| if self._reject_transport: | ||
| context = { | ||
| 'message': "Close transport, a stream was garbage collected" | ||
| 'message': ("Close transport. " | ||
| "a stream was destroyed " | ||
| "before connection establishment") | ||
|
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. |
||
| } | ||
| if self._source_traceback: | ||
| context['source_traceback'] = self._source_traceback | ||
|
|
@@ -280,6 +287,7 @@ def connection_lost(self, exc): | |
| self._stream_reader_wr = None | ||
| self._stream_writer = None | ||
| self._transport = None | ||
| print("connection lost end") | ||
|
|
||
| def data_received(self, data): | ||
| reader = self._stream_reader | ||
|
|
@@ -346,6 +354,9 @@ def can_write_eof(self): | |
| return self._transport.can_write_eof() | ||
|
|
||
| def close(self): | ||
| # a reader could be garbage collected / destroyed | ||
| # 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() | ||
|
|
||
| def is_closing(self): | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -36,6 +36,11 @@ def __repr__(self): | |
| info.append(f'stderr={self.stderr!r}') | ||
| return '<{}>'.format(' '.join(info)) | ||
|
|
||
| def _untrack_reader(self): | ||
| # a dummy placeholder subprocess protocol doesn't need it but | ||
| # the method is required for regular stream implementation. | ||
| pass | ||
|
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. |
||
|
|
||
| def connection_made(self, transport): | ||
| self._transport = transport | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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'd rephrase as: