-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-110395: invalidate open kqueues after fork #110517
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
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.
Overall I think this PR makes sense. Additional eyeballs from others such as @vstinner on what looks like module C API modernization with the tp_dealloc removal in favor of a tp_finalize would be helpful.
Make the child process _always_ exit even on test failure.
I double checked the tp_dealloc and tp_finalize stuff and gave this another look. it's good, thanks! |
Thanks for the review! CI failure looks spurious and unrelated to this change. Anything else I have to do? |
test_asyncio test_unhandled_exceptions() failed on Windows x86: it's a known bug, fixed in the main branch. I re-run the job. If it fails too often, you can consider to rebase your PR on the main branch to get my test_unhandled_exceptions() fix. |
Sorry, @sorcio and @gpshead, I could not cleanly backport this to
|
…110517) Invalidate open select.kqueue instances after fork as the fd will be invalid in the child. (cherry picked from commit a6c1c04) Co-authored-by: Davide Rizzo <[email protected]>
…110517) Invalidate open select.kqueue instances after fork as the fd will be invalid in the child. (cherry picked from commit a6c1c04) Co-authored-by: Davide Rizzo <[email protected]>
GH-111745 is a backport of this pull request to the 3.12 branch. |
…1745) * [3.12] gh-110395: invalidate open kqueues after fork (GH-110517) Invalidate open select.kqueue instances after fork as the fd will be invalid in the child. (cherry picked from commit a6c1c04) Co-authored-by: Davide Rizzo <[email protected]> * move assert to after the child dying this is in `main` via https://github.com/python/cpython/pull/111816/files
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
Track
select.kqueue
objects with an open fd in a linked list, so they can be invalidated after fork. The invalidation happens throughposix.register_at_fork()
for lack of a better/safer idea.This PR does some extra allocations, but the number of kqueues you'll open in a program is normally very small, and otherwise it's very lightweight (tracking is only involved at open/close/fork).
I thought of different approaches but I'm not convinced:
.detach()
method to invalidate the object without closing the fd. Leaves the burden of correct cleanup to users.close()
on object destructor. Might make sense if combined with a check on pid at creation/destruction time. But still leaves some burden to users.