bpo-31647: Fix write_eof() after close() for SelectorSocketTransport (GH-7149) (#7154)

Fixed bug where calling write_eof() on a _SelectorSocketTransport after
it's already closed raises AttributeError.
(cherry picked from commit 23f587e395)

Co-authored-by: twisteroid ambassador <twisteroidambassador@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2018-05-28 13:25:03 -07:00 committed by Yury Selivanov
parent c489a767af
commit 7e8819a589
3 changed files with 9 additions and 1 deletions

View File

@ -804,7 +804,7 @@ class _SelectorSocketTransport(_SelectorTransport):
self._sock.shutdown(socket.SHUT_WR) self._sock.shutdown(socket.SHUT_WR)
def write_eof(self): def write_eof(self):
if self._eof: if self._closing or self._eof:
return return
self._eof = True self._eof = True
if not self._buffer: if not self._buffer:

View File

@ -1187,6 +1187,12 @@ class SelectorSocketTransportTests(test_utils.TestCase):
self.sock.shutdown.assert_called_with(socket.SHUT_WR) self.sock.shutdown.assert_called_with(socket.SHUT_WR)
tr.close() tr.close()
def test_write_eof_after_close(self):
tr = self.socket_transport()
tr.close()
self.loop.run_until_complete(asyncio.sleep(0))
tr.write_eof()
@mock.patch('asyncio.base_events.logger') @mock.patch('asyncio.base_events.logger')
def test_transport_close_remove_writer(self, m_log): def test_transport_close_remove_writer(self, m_log):
remove_writer = self.loop._remove_writer = mock.Mock() remove_writer = self.loop._remove_writer = mock.Mock()

View File

@ -0,0 +1,2 @@
Fixed bug where calling write_eof() on a _SelectorSocketTransport after it's
already closed raises AttributeError.