]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33833: Fix ProactorSocketTransport AssertionError (#7893)
authortwisteroid ambassador <twisteroidambassador@users.noreply.github.com>
Mon, 30 Jul 2018 18:58:50 +0000 (02:58 +0800)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Mon, 30 Jul 2018 18:58:50 +0000 (21:58 +0300)
Lib/asyncio/proactor_events.py
Lib/test/test_asyncio/test_proactor_events.py
Misc/NEWS.d/next/Library/2018-06-17-11-46-20.bpo-33833.RnEqvM.rst [new file with mode: 0644]

index 6d230a2d17734eaf3ced67f7e1ef9107be24c016..66bfb0ab11ee50c4887574a9f2d380a6ae3ee243 100644 (file)
@@ -343,6 +343,10 @@ class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,
 
     def _loop_writing(self, f=None, data=None):
         try:
+            if f is not None and self._write_fut is None and self._closing:
+                # XXX most likely self._force_close() has been called, and
+                # it has set self._write_fut to None.
+                return
             assert f is self._write_fut
             self._write_fut = None
             self._pending_write = 0
index ac529413c2756bb0477a89daaebc6b2bebf0b065..dddbe3b2a107ca621e49714be625f67904586672 100644 (file)
@@ -257,6 +257,19 @@ class ProactorSocketTransportTests(test_utils.TestCase):
         self.assertEqual(None, tr._buffer)
         self.assertEqual(tr._conn_lost, 1)
 
+    def test_loop_writing_force_close(self):
+        exc_handler = mock.Mock()
+        self.loop.set_exception_handler(exc_handler)
+        fut = asyncio.Future(loop=self.loop)
+        fut.set_result(1)
+        self.proactor.send.return_value = fut
+
+        tr = self.socket_transport()
+        tr.write(b'data')
+        tr._force_close(None)
+        test_utils.run_briefly(self.loop)
+        exc_handler.assert_not_called()
+
     def test_force_close_idempotent(self):
         tr = self.socket_transport()
         tr._closing = True
diff --git a/Misc/NEWS.d/next/Library/2018-06-17-11-46-20.bpo-33833.RnEqvM.rst b/Misc/NEWS.d/next/Library/2018-06-17-11-46-20.bpo-33833.RnEqvM.rst
new file mode 100644 (file)
index 0000000..1a7672f
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed bug in asyncio where ProactorSocketTransport logs AssertionError if
+force closed during write.