[Python-checkins] bpo-31647: Fix write_eof() after close() for SelectorSocketTransport (GH-7149) (GH-7153)

Yury Selivanov webhook-mailer at python.org
Mon May 28 12:04:12 EDT 2018


https://github.com/python/cpython/commit/1f21ae710d83a37c872355612b58958cef4d5f95
commit: 1f21ae710d83a37c872355612b58958cef4d5f95
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yury Selivanov <yury at magic.io>
date: 2018-05-28T12:04:09-04:00
summary:

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

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

Co-authored-by: twisteroid ambassador <twisteroidambassador at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2018-05-28-18-40-26.bpo-31467.s4Fad3.rst
M Lib/asyncio/selector_events.py
M Lib/test/test_asyncio/test_selector_events.py

diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index f9533a1d77be..5473c7055212 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -899,7 +899,7 @@ def _write_ready(self):
                     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 684c29dec3e2..5c4ff5745b62 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -1263,6 +1263,12 @@ def test_write_eof_buffer(self):
         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 000000000000..61cc8baa1cd5
--- /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.



More information about the Python-checkins mailing list