Skip to content

gh-90622: Prevent concurrent.futures.process deadlock due to fork() after spawning a thread. #30847

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

Closed
wants to merge 4 commits into from

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Jan 24, 2022

1ac6e37 released in 3.9 as a performance enhancement to concurrent.futures introduced a deadlock in some environments by violating the POSIX spec with new child processes being fork()ed after a thread had been started. This reverts that. It also reverts fdc0e09 which tried to add a new max_tasks_per_child feature for 3.11 that built upon the previous ill fated 3.9 performance enhancement.

There is a better way to do this that would not fork after starting a thread, but implementing that is a much larger architectural enhancement; not something that could be back-ported as a bug fix.

The 3.10 backport will need to be manual as it doesn't have the 3.11 change. The 3.9 one can be autogenerated from that. Alternatively I could split this PR into two separate rollbacks.

https://bugs.python.org/issue46464

…thonGH-27373)"

This reverts commit fdc0e09.

This implementation relies on a mechanism for spawning new children
dynamically rather than up front that leads to deadlocks due to mixing
of threads+fork.  See bpo-46464.
bpo-39207: Spawn workers on demand in ProcessPoolExecutor (pythonGH-19453) was
implemented in a way that introduced child process deadlocks in some
environments due to mixing threading and fork() in the parent process.
@gpshead gpshead added type-bug An unexpected behavior, bug, or error needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Jan 24, 2022
@gpshead gpshead marked this pull request as ready for review January 24, 2022 08:57
@gpshead gpshead requested a review from pitrou January 25, 2022 01:19
@gpshead gpshead marked this pull request as draft January 25, 2022 02:25
@gpshead gpshead requested a review from methane January 25, 2022 02:26
@gpshead
Copy link
Member Author

gpshead commented Jan 25, 2022

See bug discussion. It looks like this will split into 2 and the max_tasks_per_child feature can be kept so long as it becomes an error when a 'fork' mp_context would be used.

@gpshead gpshead changed the title bpo-46464: Prevent concurrent.futures.process deadlock due to fork() after spawning a thread. gh-90622: Prevent concurrent.futures.process deadlock due to fork() after spawning a thread. Apr 16, 2022
@gpshead gpshead closed this May 13, 2022
@gpshead gpshead deleted the bpo46464-deadlock branch May 13, 2022 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants