Skip to content
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

gh-109981: Fix support.fd_count() on macOS 14 #112797

Merged
merged 3 commits into from
Dec 7, 2023

Conversation

ronaldoussoren
Copy link
Contributor

@ronaldoussoren ronaldoussoren commented Dec 6, 2023

This fixes a crash on macOS 14 when
running ./python.exe -m test test_sax test_socket test_support.

The root cause of this is a macOS feature where file descriptors used by system libraries are guarded an will cause a hard crash when used in "user" code.

This fixes a crash on macOS 14 when
running ``./python.exe -m test test_sax test_socket test_support``.

The root cause of this is a macOS feature where file
descriptors used by system libraries are guarded an will
cause a hard crash when used in "user" code.
@ronaldoussoren ronaldoussoren requested a review from a team December 6, 2023 11:24
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but:

  • I made a minor coding style suggestion.
  • The PR title is misleading. What does "test crash" means? I suggest to refer to support.fd_count() instead. For example, "Fix support.fd_count() on macOS".

Lib/test/support/os_helper.py Outdated Show resolved Hide resolved
@vstinner
Copy link
Member

vstinner commented Dec 6, 2023

On FreeBSD, maybe we should try /dev/fd/ and then /proc/self/fd/. But it's unrelated to your fix, and it can be changed later.

Co-authored-by: Victor Stinner <vstinner@python.org>
@ronaldoussoren ronaldoussoren changed the title gh-109981: test crash on macOS 14 gh-109981: Fix supper.fd_count() on macOS 14 Dec 7, 2023
@ronaldoussoren
Copy link
Contributor Author

LGTM but:

  • I made a minor coding style suggestion.
  • The PR title is misleading. What does "test crash" means? I suggest to refer to support.fd_count() instead. For example, "Fix support.fd_count() on macOS".

Good suggestions. Thanks for the review!

@AlexWaygood AlexWaygood changed the title gh-109981: Fix supper.fd_count() on macOS 14 gh-109981: Fix support.fd_count() on macOS 14 Dec 7, 2023
@ronaldoussoren ronaldoussoren changed the title gh-109981: Fix support.fd_count() on macOS 14 gh-109981: Fix supper.fd_count() on macOS 14 Dec 7, 2023
@ronaldoussoren ronaldoussoren changed the title gh-109981: Fix supper.fd_count() on macOS 14 gh-109981: Fix support.fd_count() on macOS 14 Dec 7, 2023
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ronaldoussoren
Copy link
Contributor Author

On FreeBSD, maybe we should try /dev/fd/ and then /proc/self/fd/. But it's unrelated to your fix, and it can be changed later.

That should be a separate issue. I cannot easily test on FreeBSD and am not a fan of debugging through CI.

@ronaldoussoren ronaldoussoren merged commit 953ee62 into python:main Dec 7, 2023
29 checks passed
@miss-islington-app
Copy link

Thanks @ronaldoussoren for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 7, 2023
Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

(cherry picked from commit 953ee62)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112824 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Dec 7, 2023
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112825 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 7, 2023
Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

(cherry picked from commit 953ee62)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Dec 7, 2023
@ronaldoussoren ronaldoussoren deleted the gh-109981 branch December 7, 2023 09:30
ronaldoussoren added a commit that referenced this pull request Dec 7, 2023
…2824)

gh-109981: Fix support.fd_count() on macOS 14 (GH-112797)

Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

(cherry picked from commit 953ee62)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
ronaldoussoren added a commit that referenced this pull request Dec 7, 2023
…2825)

gh-109981: Fix support.fd_count() on macOS 14 (GH-112797)

Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

(cherry picked from commit 953ee62)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

Co-authored-by: Victor Stinner <vstinner@python.org>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Use scanning "/dev/fd/" on macOS in support.fd_count(). That's both more efficient than scanning all possible file descriptors, and avoids crashing the interpreter when there are open "guarded" file descriptors.

"Guarded" file descriptors are a macOS feature where file descriptors used by system libraries are marked and cause hard crashes when used by "user" code.

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants