From 23f587e395e41bd5e116312b036183f42bc4159b Mon Sep 17 00:00:00 2001 From: twisteroid ambassador Date: Mon, 28 May 2018 23:16:45 +0800 Subject: bpo-31647: Fix write_eof() after close() for SelectorSocketTransport (GH-7149) Fixed bug where calling write_eof() on a _SelectorSocketTransport after it's already closed raises AttributeError. --- Lib/asyncio/selector_events.py | 2 +- Lib/test/test_asyncio/test_selector_events.py | 6 ++++++ Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index f9533a1..5473c70 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -899,7 +899,7 @@ class _SelectorSocketTransport(_SelectorTransport): self._sock.shutdown(socket.SHUT_WR) def write_eof(self): - if self._eof: + if self._closing or self._eof: return self._eof = True if not self._buffer: diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index 684c29d..5c4ff57 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1263,6 +1263,12 @@ class SelectorSocketTransportTests(test_utils.TestCase): self.sock.shutdown.assert_called_with(socket.SHUT_WR) 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') def test_transport_close_remove_writer(self, m_log): remove_writer = self.loop._remove_writer = mock.Mock() diff --git a/Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst b/Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst new file mode 100644 index 0000000..61cc8ba --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst @@ -0,0 +1,2 @@ +Fixed bug where calling write_eof() on a _SelectorSocketTransport after it's +already closed raises AttributeError. -- cgit v0.12