mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
GH-89237: fix hang in proactor subprocess.wait_closed() (GH-98572)
(cherry picked from commit ad1dc3ebb6)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
d79a42aac8
commit
8ba086f70b
3 changed files with 10 additions and 2 deletions
|
|
@ -60,6 +60,7 @@ def __init__(self, loop, sock, protocol, waiter=None,
|
||||||
self._pending_write = 0
|
self._pending_write = 0
|
||||||
self._conn_lost = 0
|
self._conn_lost = 0
|
||||||
self._closing = False # Set when close() called.
|
self._closing = False # Set when close() called.
|
||||||
|
self._called_connection_lost = False
|
||||||
self._eof_written = False
|
self._eof_written = False
|
||||||
if self._server is not None:
|
if self._server is not None:
|
||||||
self._server._attach()
|
self._server._attach()
|
||||||
|
|
@ -136,7 +137,7 @@ def _force_close(self, exc):
|
||||||
self._empty_waiter.set_result(None)
|
self._empty_waiter.set_result(None)
|
||||||
else:
|
else:
|
||||||
self._empty_waiter.set_exception(exc)
|
self._empty_waiter.set_exception(exc)
|
||||||
if self._closing:
|
if self._closing and self._called_connection_lost:
|
||||||
return
|
return
|
||||||
self._closing = True
|
self._closing = True
|
||||||
self._conn_lost += 1
|
self._conn_lost += 1
|
||||||
|
|
@ -166,6 +167,7 @@ def _call_connection_lost(self, exc):
|
||||||
if server is not None:
|
if server is not None:
|
||||||
server._detach()
|
server._detach()
|
||||||
self._server = None
|
self._server = None
|
||||||
|
self._called_connection_lost = True
|
||||||
|
|
||||||
def get_write_buffer_size(self):
|
def get_write_buffer_size(self):
|
||||||
size = self._pending_write
|
size = self._pending_write
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,12 @@ def test_force_close_idempotent(self):
|
||||||
tr._closing = True
|
tr._closing = True
|
||||||
tr._force_close(None)
|
tr._force_close(None)
|
||||||
test_utils.run_briefly(self.loop)
|
test_utils.run_briefly(self.loop)
|
||||||
self.assertFalse(self.protocol.connection_lost.called)
|
# See https://github.com/python/cpython/issues/89237
|
||||||
|
# `protocol.connection_lost` should be called even if
|
||||||
|
# the transport was closed forcefully otherwise
|
||||||
|
# the resources held by protocol will never be freed
|
||||||
|
# and waiters will never be notified leading to hang.
|
||||||
|
self.assertTrue(self.protocol.connection_lost.called)
|
||||||
|
|
||||||
def test_fatal_error_2(self):
|
def test_fatal_error_2(self):
|
||||||
tr = self.socket_transport()
|
tr = self.socket_transport()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Fix hang on Windows in ``subprocess.wait_closed()`` in :mod:`asyncio` with :class:`~asyncio.ProactorEventLoop`. Patch by Kumar Aditya.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue