summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-07-30 20:04:30 (GMT)
committerGitHub <noreply@github.com>2018-07-30 20:04:30 (GMT)
commitd5c75be55504fae1ff510eed66cddbd27bfbdbe2 (patch)
tree9adca1e9a92be9f8a1ecf8b90f9a038cca5a93c0
parent399b47fdf6346d15579d363ddfd0661eb906699e (diff)
downloadcpython-d5c75be55504fae1ff510eed66cddbd27bfbdbe2.zip
cpython-d5c75be55504fae1ff510eed66cddbd27bfbdbe2.tar.gz
cpython-d5c75be55504fae1ff510eed66cddbd27bfbdbe2.tar.bz2
bpo-33833: Fix ProactorSocketTransport AssertionError (GH-7893)
(cherry picked from commit 9045199c5aaeac9b52537581be127d999b5944ee) Co-authored-by: twisteroid ambassador <twisteroidambassador@users.noreply.github.com>
-rw-r--r--Lib/asyncio/proactor_events.py4
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py13
-rw-r--r--Misc/NEWS.d/next/Library/2018-06-17-11-46-20.bpo-33833.RnEqvM.rst2
3 files changed, 19 insertions, 0 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 6d230a2..66bfb0a 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -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
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index 557b461..56f77ad 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -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
index 0000000..1a7672f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-17-11-46-20.bpo-33833.RnEqvM.rst
@@ -0,0 +1,2 @@
+Fixed bug in asyncio where ProactorSocketTransport logs AssertionError if
+force closed during write.