gh-153400: Use glibc functions instead of syscall() by vstinner · Pull Request #155518 · python/cpython · GitHub
Skip to content

gh-153400: Use glibc functions instead of syscall() - #155518

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:pidfd
Aug 13, 2026
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:pidfd

Conversation

@vstinner

@vstinner vstinner commented Aug 10, 2026

Copy link
Copy Markdown
Member

Use glibc functions instead of syscall(): pidfd_open(), pidfd_getfd() and pidfd_send_signal() (glibc 2.36), gettid() and getdents64() (glibc 2.30), and getrandom() (glibc 2.25).

Use unsigned int for os.getrandom() flags and signal.pidfd_send_signal() flags.

Use glibc functions instead of syscall(): pidfd_open(), pidfd_getfd()
and pidfd_send_signal() (glibc 2.36), gettid() and getdents64()
(glibc 2.30), and getrandom() (glibc 2.25).
@vstinner
vstinner requested a review from gpshead as a code owner August 10, 2026 21:06
@vstinner vstinner changed the title gh-153400: Use pidfd_open() and pidfd_getfd() functions gh-153400: Use glibc functions instead of syscall() Aug 10, 2026
Use unsigned int for os.getrandom() flags and
signal.pidfd_send_signal() flags.
@vstinner

Copy link
Copy Markdown
Member Author

@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 11, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit b6bbfd9 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F155518%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 11, 2026
@thesamesam

Copy link
Copy Markdown
Contributor

I wrote this change to replace syscall() calls with glibc function calls here instead. Is it what you proposed?

It looks good, thank you!

@vstinner

Copy link
Copy Markdown
Member Author

buildbot/AMD64 Android PR — Build done.

The "test" step failed with a timeout, not good. I'm not sure if it's related to the change or not.

@mhsmith

mhsmith commented Aug 11, 2026

Copy link
Copy Markdown
Member

!buildbot AMD64 Android

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @mhsmith for commit b6bbfd9 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F155518%2Fmerge

The command will test the builders whose names match following regular expression: AMD64 Android

The builders matched are:

  • AMD64 Android PR

@mhsmith

mhsmith commented Aug 11, 2026

Copy link
Copy Markdown
Member

The buildbot stopped working about 24 hours ago, so it's not related to this change. Testing manually, it appeared to work on the first run within each Gradle daemon, but if I interrupted it and tried again, it hung while starting the emulator. Removing the emulator snapshot and allowing it to be recreated seems to have fixed the issue.

@mhsmith

mhsmith commented Aug 11, 2026

Copy link
Copy Markdown
Member

No, apparently not, and it looks like this previously happened for a few runs in a row on August 5, then again on August 6.

In each case, it was triggered by a run that was cancelled for some reason, such as a master shutdown. Subsequent runs then stop at the line > Task :app:maxVersionDebugAndroidTest, and time out after 10 minutes without having started the emulator. The problem persists until there's a long enough gap between runs for the broken Gradle daemon to time out. So this was probably caused by the Gradle update on August 1 (#155012).

I'll shut the buildbot down until I have a chance to look into this. Notes to self:

  • Check the version of platform-tools, emulator, or any other SDK packages that may be involved. Match the versions on GitHub Actions, or the other buildbot, but keep a record of the previous versions (see notes in Android buildbot failures after updating to API level 35 #142387).
  • Switch to Java 25, since that's what this version of AGP is best tested with.
  • Switch to an older version of AGP which is still compatible with Java 25.
  • Revert the update completely.

We still have x86_64 being tested by GitHub Actions, and aarch64 by the other buildbot, so it doesn't need to block this PR.

@vstinner
vstinner merged commit 1c9521f into python:main Aug 13, 2026
141 of 142 checks passed
@vstinner
vstinner deleted the pidfd branch August 13, 2026 10:44
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
)

Use glibc functions instead of syscall(): pidfd_open(), pidfd_getfd()
and pidfd_send_signal() (glibc 2.36), gettid() and getdents64()
(glibc 2.30), and getrandom() (glibc 2.25).

Use unsigned int for os.getrandom() flags and
signal.pidfd_send_signal() flags.
@mhsmith

mhsmith commented Sep 7, 2026

Copy link
Copy Markdown
Member

I didn't try any of the ideas above, because although I reproduced the problem several times, I wasn't able to do it reliably, so I'd have no way of knowing whether anything worked. None of the following things were good enough:

  • Interrupting multiple runs in a row
  • Interrupting quickly or slowly
  • Running git clean or gradlew clean between runs

Instead, since the problem involves the Gradle daemon getting into a broken state, I disabled persistent daemons by adding this line to the worker startup script:

export GRADLE_OPTS="-Dorg.gradle.daemon=false"

This should make each run more independent, as it is on GitHub Actions. It only costs about 20 seconds per run.

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[post merge review] confirming that this is safe. glibc's struct dirent64 is as above and has 256 bytes of d_name space declared. I think the linux kernel itself uses a sizeless d_name[] to expect the caller to allocate extra. if that happened here we'd wind up with a tiny struct without necessarily room for a name and an error from the syscall, silently falling back to a slower or unsafe code path instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants