Skip to content

Commit 3b6461d

Browse files
committed
Auto merge of #158486 - valentynkit:pidfd-enfile-transient, 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` (#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
2 parents b4486ca + 77e396d commit 3b6461d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • library/std/src/sys/process/unix

library/std/src/sys/process/unix/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ impl Command {
510510
support = SPAWN;
511511
}
512512
}
513-
Err(e) if e.raw_os_error() == Some(libc::EMFILE) => {
514-
// We're temporarily(?) out of file descriptors. In this case pidfd_spawnp would also fail
513+
Err(e) if matches!(e.raw_os_error(), Some(libc::EMFILE | libc::ENFILE | libc::ENOMEM)) => {
514+
// We're temporarily(?) out of file descriptors or memory. In this case pidfd_spawnp would also fail
515515
// Don't update the support flag so we can probe again later.
516516
return Err(e)
517517
}

0 commit comments

Comments
 (0)