diff options
author | twisteroid ambassador <twisteroidambassador@users.noreply.github.com> | 2018-05-28 15:16:45 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2018-05-28 15:16:45 (GMT) |
commit | 23f587e395e41bd5e116312b036183f42bc4159b (patch) | |
tree | 2a6453563194a9a1cba255b08a2c9a2d27810da0 | |
parent | 35230d08e09de4e2e52658d5cb09e5b0ca965418 (diff) | |
download | cpython-23f587e395e41bd5e116312b036183f42bc4159b.zip cpython-23f587e395e41bd5e116312b036183f42bc4159b.tar.gz cpython-23f587e395e41bd5e116312b036183f42bc4159b.tar.bz2 |
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.
-rw-r--r-- | Lib/asyncio/selector_events.py | 2 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_selector_events.py | 6 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst | 2 |
3 files changed, 9 insertions, 1 deletions
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. |