Skip to content

Conversation

@vinDelphini
Copy link
Contributor

Fixes a FIXME in sys/fs/unix.rs.

Currently, if the statx availability probe fails with ENOMEM, statx is permanently disabled for the process. Since ENOMEM is transient, this change allows falling back to stat for the current call without updating STATX_SAVED_STATE to Unavailable, permitting statx to be retried later.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 25, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2026

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@vinDelphini vinDelphini force-pushed the bugfix/statx-enomem-clean branch from 54e20c5 to d9404ad Compare January 25, 2026 11:37
//
// See: https://github.com/rust-lang/rust/issues/65662
//
// FIXME what about transient conditions like `ENOMEM`?
Copy link
Contributor

@terrarier2111 terrarier2111 Jan 25, 2026

Choose a reason for hiding this comment

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

Are you sure there are no other transient coditions (other than ENOMEM) that we should worry about here?
As the comment says "like" which indicates to me as an uninformed reader, that there may be more transient conditions to consider other than ENOMEM.
If so, removing this comment is not correct IMHO.

Copy link
Contributor Author

@vinDelphini vinDelphini Jan 25, 2026

Choose a reason for hiding this comment

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

ya true, deleting the comment was premature...

One concern I have is that caching STATX_STATE::Unavailable feels risky if the failure is transient, since that would effectively disable statx for the lifetime of the process.

  1. Should Unavailable be cached only for ENOSYS, or also cases like EPERM (seccomp)?
  2. For other errors that aren’t clearly “missing” or transient, is it better to avoid caching and just fall back to legacy stat for that call?
  3. Any other transient errors you’d want handled explicitly?

If this needs a bit more discussion, I could open a GitHub issue first, please suggest, thanks mate! @terrarier2111 @ibraheemdev

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to discuss here since this is where we would see the changes anyway.

One concern I have is that caching STATX_STATE::Unavailable feels risky if the failure is transient, since that would effectively disable statx for the lifetime of the process.

There is nothing "risky" about using the stat fallback.

  • For other errors that aren’t clearly “missing” or transient, is it better to avoid caching and just fall back to legacy stat for that call?
  • Any other transient errors you’d want handled explicitly?

It's your PR, could you propose a reasonable solution here? :)

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

I don't think it's the worst thing to allow a retry on ENOMEM, but this code changes more than just the ENOMEM handling.

As an alternative we could keep a retry counter and fall back if it fails a number of times, but things are going rather poorly if you get a repeated kernel OOM from an empty statx. I don't really think it's worth it.

@tbu- it looks like you've touched this code most recently, do you have any thoughts?

View changes since this review

Comment on lines +201 to +210
match cvt(statx(
0,
ptr::null(),
0,
libc::STATX_BASIC_STATS | libc::STATX_BTIME,
ptr::null_mut(),
))
.err()
.and_then(|e| e.raw_os_error())
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep the err2 binding and then match on that, it reads significantly better

Comment on lines 197 to +201
// See: https://github.com/rust-lang/rust/issues/65662
//
// FIXME what about transient conditions like `ENOMEM`?
let err2 = cvt(statx(0, ptr::null(), 0, libc::STATX_BASIC_STATS | libc::STATX_BTIME, ptr::null_mut()))
.err()
.and_then(|e| e.raw_os_error());
if err2 == Some(libc::EFAULT) {
STATX_SAVED_STATE.store(STATX_STATE::Present as u8, Ordering::Relaxed);
return Some(Err(err));
} else {
STATX_SAVED_STATE.store(STATX_STATE::Unavailable as u8, Ordering::Relaxed);
return None;


match cvt(statx(
Copy link
Contributor

Choose a reason for hiding this comment

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

Clean up this spacing; the comment was previously attached to the the next line of code. Now there is an empty // line at the end of the comment block and two newlines before the line of code.

Comment on lines +210 to 219
{
Some(libc::EFAULT) => {
STATX_SAVED_STATE.store(STATX_STATE::Present as u8, Ordering::Relaxed);
return Some(Err(err));
}
Some(libc::ENOSYS | libc::EPERM | libc::EACCES) => {
STATX_SAVED_STATE.store(STATX_STATE::Unavailable as u8, Ordering::Relaxed);
}
_ => {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, allowing a retry on any error condition aside from the few listed is not robust. Compare to the original implementation.

STATX_SAVED_STATE.store(STATX_STATE::Present as u8, Ordering::Relaxed);
return Some(Err(err));
}
Some(libc::ENOSYS | libc::EPERM | libc::EACCES) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did this selection come from?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants