]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33833: Fix ProactorSocketTransport AssertionError (GH-7893)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 30 Jul 2018 20:04:30 +0000 (13:04 -0700)
committerGitHub <noreply@github.com>
Mon, 30 Jul 2018 20:04:30 +0000 (13:04 -0700)
(cherry picked from commit 9045199c5aaeac9b52537581be127d999b5944ee)

Co-authored-by: twisteroid ambassador <twisteroidambassador@users.noreply.github.com>
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 557b461750a1d3b56efddde870fc7e125179474c..56f77ad945af181f2741422022603f43678023fe 100644 (file)
@@ -253,6 +253,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.