gh-84579: Fixed a deadlock issue in the bufferedIO module when using fork in Py…#128591
gh-84579: Fixed a deadlock issue in the bufferedIO module when using fork in Py…#128591LuYanFCP 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 |
| } | ||
|
|
||
| /* Create method objects */ | ||
| PyObject *after_child = PyCFunction_New(&buffered_fork_methods[0], (PyObject *)self); |
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.
|
|
||
| /* Append callbacks to the lists */ | ||
| int status = 0; | ||
| if (PyList_Append(interp->after_forkers_child, after_child) < 0) { |
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 PR is stale because it has been open for 30 days with no activity. |
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.