summaryrefslogtreecommitdiffstats
path: root/Lib/concurrent
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-11 08:11:31 (GMT)
committerGitHub <noreply@github.com>2023-09-11 08:11:31 (GMT)
commita9b1f84790e977fb09f75b148c4c4f5924a6ef99 (patch)
tree836a2e8244e2bcafa81cddaeb88e8489f63231b0 /Lib/concurrent
parent3b2ecbc1275bd05534885cee9ac1389987238561 (diff)
downloadcpython-a9b1f84790e977fb09f75b148c4c4f5924a6ef99.zip
cpython-a9b1f84790e977fb09f75b148c4c4f5924a6ef99.tar.gz
cpython-a9b1f84790e977fb09f75b148c4c4f5924a6ef99.tar.bz2
gh-107219: Fix concurrent.futures terminate_broken() (#109244)
Fix a race condition in concurrent.futures. When a process in the process pool was terminated abruptly (while the future was running or pending), close the connection write end. If the call queue is blocked on sending bytes to a worker process, closing the connection write end interrupts the send, so the queue can be closed. Changes: * _ExecutorManagerThread.terminate_broken() now closes call_queue._writer. * multiprocessing PipeConnection.close() now interrupts WaitForMultipleObjects() in _send_bytes() by cancelling the overlapped operation.
Diffstat (limited to 'Lib/concurrent')
-rw-r--r--Lib/concurrent/futures/process.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index 9933d3d..f4b5cd1 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -510,6 +510,10 @@ class _ExecutorManagerThread(threading.Thread):
# https://github.com/python/cpython/issues/94777
self.call_queue._reader.close()
+ # gh-107219: Close the connection writer which can unblock
+ # Queue._feed() if it was stuck in send_bytes().
+ self.call_queue._writer.close()
+
# clean up resources
self.join_executor_internals()