Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix notes
  • Loading branch information
asvetlov committed Sep 12, 2018
commit ced1bd2720c30f44c08678f52db11096ff324d92
19 changes: 9 additions & 10 deletions Lib/asyncio/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

# This is a stream created by the `create_server()` function.
# Keep a strong reference to the reader until a connection 
# is established.

self._reject_connection = False
self._stream_writer = None
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

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.

# The reader can be safely garbage collected after 
# closing the connection.

self._protocol._untrack_reader()
return self._transport.close()
Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,8 @@ def test_del_stream_before_sock_closing(self):
self.assertEqual(sock.fileno(), -1)

self.assertEqual(1, len(messages))
self.assertEqual('Close transport. A stream was destroyed '
'without stream.close() call',
self.assertEqual('An open stream object is being garbage '
'collected; call "stream.close()" explicitly.',
messages[0]['message'])

def test_del_stream_before_connection_made(self):
Expand All @@ -959,8 +959,9 @@ def test_del_stream_before_connection_made(self):
self.assertEqual(sock.fileno(), -1)

self.assertEqual(1, len(messages))
self.assertEqual('Close transport. a stream was destroyed '
'before connection establishment',
self.assertEqual('An open stream was garbage collected prior to '
'establishing network connection; '
'call "stream.close()" explicitly.',
messages[0]['message'])


Expand Down