gh-84579: Fixed a deadlock issue in the bufferedIO module when using fork in Py…#128591
Draft
LuYanFCP wants to merge 1 commit intopython:mainfrom
Draft
gh-84579: Fixed a deadlock issue in the bufferedIO module when using fork in Py…#128591LuYanFCP wants to merge 1 commit intopython:mainfrom
LuYanFCP wants to merge 1 commit intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Zheaoli
reviewed
Jan 8, 2025
| } | ||
|
|
||
| /* Create method objects */ | ||
| PyObject *after_child = PyCFunction_New(&buffered_fork_methods[0], (PyObject *)self); |
Contributor
There was a problem hiding this comment.
For me, this is not true here.
If you try to register a callback for every buffer object. I think there would be memory leak here.
Zheaoli
reviewed
Jan 8, 2025
|
|
||
| /* Append callbacks to the lists */ | ||
| int status = 0; | ||
| if (PyList_Append(interp->after_forkers_child, after_child) < 0) { |
Contributor
There was a problem hiding this comment.
If I'm correct, I think the length of after_forkers_child will raising unlimited?
e46e1de to
f8e27c0
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #84579
[BUG] Fix deadlock in BufferedIO after fork in child process
The current implementation of BufferedIO can lead to a deadlock situation in child processes after fork() due to inherited lock states from the parent process's buffer protection mechanism.
Problem
When a Python process forks, the child process inherits the lock state of BufferedIO's internal buffer protection from its parent. This inherited lock state can cause deadlocks in the child process when attempting to perform I/O operations.
Solution
buffered_after_fork_child_impl()to properly initialize buffer and lock states in child processesPyOS_AfterFork_Child()to ensure proper buffer state reset after forkTarget Issues
This fix is particularly important for applications that rely on process forking and perform I/O operations in child processes.
Note: This change only affects Unix-like systems where fork() is available.