Skip to content

std: treat ENFILE as transient in the pidfd support probe#158486

Open
valentynkit wants to merge 2 commits into
rust-lang:mainfrom
valentynkit:pidfd-enfile-transient
Open

std: treat ENFILE as transient in the pidfd support probe#158486
valentynkit wants to merge 2 commits into
rust-lang:mainfrom
valentynkit:pidfd-enfile-transient

Conversation

@valentynkit

@valentynkit valentynkit commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

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:

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
(#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

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.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 27, 2026

@joboet joboet 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.

Thanks! Would you mind adding ENOMEM to the list, too? It's the same kind of ephemeral error.

View changes since this review

@joboet

joboet commented Jun 27, 2026

Copy link
Copy Markdown
Member

r? joboet

@rustbot rustbot assigned joboet and unassigned JohnTitor Jun 27, 2026
@valentynkit

Copy link
Copy Markdown
Contributor Author

Done, added ENOMEM. Also broadened the comment since it's no longer only fds.

@joboet

joboet commented Jun 28, 2026

Copy link
Copy Markdown
Member

Perfect, thanks!
@bors r+

@rust-bors

rust-bors Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 77e396d has been approved by joboet

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2026
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants