gh-110395: invalidate open kqueues after fork#110517
Merged
gpshead merged 3 commits intopython:mainfrom Nov 4, 2023
Merged
Conversation
Make the child process _always_ exit even on test failure.
gpshead
approved these changes
Nov 3, 2023
Member
|
I double checked the tp_dealloc and tp_finalize stuff and gave this another look. it's good, thanks! |
Contributor
Author
|
Thanks for the review! CI failure looks spurious and unrelated to this change. Anything else I have to do? |
Member
|
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 |
|
GH-111745 is a backport of this pull request to the 3.12 branch. |
gpshead
added a commit
that referenced
this pull request
Nov 11, 2023
…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 <sorcio@gmail.com> * move assert to after the child dying this is in `main` via https://github.com/python/cpython/pull/111816/files
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
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.
Track
select.kqueueobjects 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.