bpo-33833: Fix ProactorSocketTransport AssertionError (GH-7893)
(cherry picked from commit 9045199c5a
)
Co-authored-by: twisteroid ambassador <twisteroidambassador@users.noreply.github.com>
This commit is contained in:
parent
399b47fdf6
commit
d5c75be555
|
@ -343,6 +343,10 @@ class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,
|
||||||
|
|
||||||
def _loop_writing(self, f=None, data=None):
|
def _loop_writing(self, f=None, data=None):
|
||||||
try:
|
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
|
assert f is self._write_fut
|
||||||
self._write_fut = None
|
self._write_fut = None
|
||||||
self._pending_write = 0
|
self._pending_write = 0
|
||||||
|
|
|
@ -253,6 +253,19 @@ class ProactorSocketTransportTests(test_utils.TestCase):
|
||||||
self.assertEqual(None, tr._buffer)
|
self.assertEqual(None, tr._buffer)
|
||||||
self.assertEqual(tr._conn_lost, 1)
|
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):
|
def test_force_close_idempotent(self):
|
||||||
tr = self.socket_transport()
|
tr = self.socket_transport()
|
||||||
tr._closing = True
|
tr._closing = True
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed bug in asyncio where ProactorSocketTransport logs AssertionError if
|
||||||
|
force closed during write.
|
Loading…
Reference in New Issue