diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-24 20:42:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 20:42:20 (GMT) |
commit | 8ba086f70b593fcdd2dc63d516af8e7240a9d28d (patch) | |
tree | 931c7036c3fe2ea80985841d6c536d4ad0b8c831 | |
parent | d79a42aac83a5420d47ecfffffebcdcecb3cf2d0 (diff) | |
download | cpython-8ba086f70b593fcdd2dc63d516af8e7240a9d28d.zip cpython-8ba086f70b593fcdd2dc63d516af8e7240a9d28d.tar.gz cpython-8ba086f70b593fcdd2dc63d516af8e7240a9d28d.tar.bz2 |
GH-89237: fix hang in proactor `subprocess.wait_closed()` (GH-98572)
(cherry picked from commit ad1dc3ebb6aadaeeeacde13d4ed2d62bf302bf62)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
-rw-r--r-- | Lib/asyncio/proactor_events.py | 4 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_proactor_events.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-10-23-18-30-39.gh-issue-89237.kBui30.rst | 1 |
3 files changed, 10 insertions, 2 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 9657f96..610d673 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -60,6 +60,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, self._pending_write = 0 self._conn_lost = 0 self._closing = False # Set when close() called. + self._called_connection_lost = False self._eof_written = False if self._server is not None: self._server._attach() @@ -136,7 +137,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, self._empty_waiter.set_result(None) else: self._empty_waiter.set_exception(exc) - if self._closing: + if self._closing and self._called_connection_lost: return self._closing = True self._conn_lost += 1 @@ -166,6 +167,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, if server is not None: server._detach() self._server = None + self._called_connection_lost = True def get_write_buffer_size(self): size = self._pending_write diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index fc6ee1c..3b21960 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -289,7 +289,12 @@ class ProactorSocketTransportTests(test_utils.TestCase): tr._closing = True tr._force_close(None) 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): tr = self.socket_transport() diff --git a/Misc/NEWS.d/next/Library/2022-10-23-18-30-39.gh-issue-89237.kBui30.rst b/Misc/NEWS.d/next/Library/2022-10-23-18-30-39.gh-issue-89237.kBui30.rst new file mode 100644 index 0000000..668ea4c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-23-18-30-39.gh-issue-89237.kBui30.rst @@ -0,0 +1 @@ +Fix hang on Windows in ``subprocess.wait_closed()`` in :mod:`asyncio` with :class:`~asyncio.ProactorEventLoop`. Patch by Kumar Aditya. |