-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-84579: Fixed a deadlock issue in the bufferedIO module when using fork in Py… #128591
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.