std: treat ENFILE as transient in the pidfd support probe#158486
Open
valentynkit wants to merge 2 commits into
Open
std: treat ENFILE as transient in the pidfd support probe#158486valentynkit wants to merge 2 commits into
valentynkit wants to merge 2 commits into
Conversation
The probe handles EMFILE (per-process fd limit) as a transient error and re-probes later, but lets ENFILE (system-wide fd limit) fall through to the catch-all arm meant for an old kernel without pidfd support, which permanently caches the pidfd path as unsupported. ENFILE is the same transient condition, so handle both.
joboet
approved these changes
Jun 27, 2026
Member
|
r? joboet |
Contributor
Author
|
Done, added |
Member
|
Perfect, thanks! |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jun 28, 2026
…, r=joboet
std: treat ENFILE as transient in the pidfd support probe
The pidfd support probe special-cases `EMFILE` from `pidfd_open`: it returns the
error without caching anything, so the next spawn re-probes. `ENFILE` falls
through instead, into the fallback arm, so the probe caches pidfd as unsupported
for the rest of the process, even after descriptors free up.
Both errnos come from the same `pidfd_open` call and mean the same thing: the
process is out of file descriptors, just per-process (`EMFILE`) vs system-wide
(`ENFILE`). I don't see a reason to treat them differently here, so this handles
`ENFILE` the same way:
```rust
Err(e) if matches!(e.raw_os_error(), Some(libc::EMFILE | libc::ENFILE)) => {
```
I kept the raw `raw_os_error()` check rather than `ErrorKind::TooManyOpenFiles`
(rust-lang#158326, which maps both) to match the rest of this probe, but can switch if
you'd prefer.
I didn't add a test, since triggering it needs real fd exhaustion during the
probe, which isn't practical to reproduce. The `EMFILE` arm isn't tested either.
r? libs
rust-bors Bot
pushed a commit
that referenced
this pull request
Jun 28, 2026
…uwer Rollup of 4 pull requests Successful merges: - #158486 (std: treat ENFILE as transient in the pidfd support probe) - #158454 (regression test for `Trait<A><B>` in "consider further restricting this bound" suggestion) - #158518 (Fix mixed use of "a" / "an" article in E0277) - #158519 (add crashtests [2/N])
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.
The pidfd support probe special-cases
EMFILEfrompidfd_open: it returns theerror without caching anything, so the next spawn re-probes.
ENFILEfallsthrough instead, into the fallback arm, so the probe caches pidfd as unsupported
for the rest of the process, even after descriptors free up.
Both errnos come from the same
pidfd_opencall and mean the same thing: theprocess is out of file descriptors, just per-process (
EMFILE) vs system-wide(
ENFILE). I don't see a reason to treat them differently here, so this handlesENFILEthe same way:I kept the raw
raw_os_error()check rather thanErrorKind::TooManyOpenFiles(#158326, which maps both) to match the rest of this probe, but can switch if
you'd prefer.
I didn't add a test, since triggering it needs real fd exhaustion during the
probe, which isn't practical to reproduce. The
EMFILEarm isn't tested either.r? libs