-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-39995: Fix concurrent.futures _ThreadWakeup #19760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix a race condition in concurrent.futures._ThreadWakeup: access to _ThreadWakeup is now protected with the shutdown lock.
@@ -718,12 +733,12 @@ def shutdown(self, wait=True, *, cancel_futures=False): | |||
with self._shutdown_lock: | |||
self._cancel_pending_futures = cancel_futures | |||
self._shutdown_thread = True | |||
if self._executor_manager_thread_wakeup is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the same as both are set to None
in the same call to shutdown. (L.744/750)
This is more explicit this way so perfect.
This PR is based on @tomMoral (Thomas Moreau) idea:
I wrote a conservative change which always lock ProcessPoolExecutor._shutdown_lock while accessing _ThreadWakeup because I don't know the concurrent.futures module. Maybe we can avoid the lock in some cases. |
@pitrou @tomMoral: https://bugs.python.org/issue39995 is becoming more and more annoying for the Python CI. I suggest to start with a conservative approach to unblock https://bugs.python.org/issue39995 and then investigate where we can avoid locking. Right now, tons of test_concurrent_futures tests are failing randomly and it's becoming hard to handle all these failures and identify root issues. |
I tested manually: this PR fix test_killed_child() and ProcessPoolForkExecutorDeadlockTest tests. Using my https://bugs.python.org/msg367463 patch (sleep), without this change: it is very easy to reproduce the bug. With this change, tests no longer fail. In short, with https://bugs.python.org/msg367463 patch (sleep) and this change, only test_cancel_futures() fails: but that's expected, see https://bugs.python.org/issue39995#msg367544 |
@@ -380,7 +389,9 @@ def wait_result_broken_or_wakeup(self): | |||
|
|||
elif wakeup_reader in ready: | |||
is_broken = False | |||
self.thread_wakeup.clear() | |||
|
|||
with self.shutdown_lock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this lock is necessary as the goal is to protect against _ThreadWakeup.close
which should only be called in the same thread.
Fix a race condition in concurrent.futures._ThreadWakeup: access to
_ThreadWakeup is now protected with the shutdown lock.
https://bugs.python.org/issue39995