Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proc_self_status fails on concurrent calls #1050

Closed
niluxv opened this issue Apr 23, 2024 · 0 comments · Fixed by #1059
Closed

proc_self_status fails on concurrent calls #1050

niluxv opened this issue Apr 23, 2024 · 0 comments · Fixed by #1059

Comments

@niluxv
Copy link
Contributor

niluxv commented Apr 23, 2024

proc_self_status again... It fails when called multiple times concurrently. On versions 0.18.14 and less it works fine, so I suppose this is not expected behaviour. If it is, then that definitely needs to be documented.

Example

const THREADS: usize = 3;

fn self_proc_status() {
    rustix::procfs::proc_self_status().expect("error getting proc/self/status pid");
}

#[test]
fn parallel_self_proc_status() {
    let mut handles = Vec::with_capacity(THREADS);
    for _ in 0..THREADS {
        handles.push(std::thread::spawn(self_proc_status));
    }
    for handle in handles.drain(..) {
        handle.join().expect("thread crashed");
    }
}

Outputs:

---- parallel_self_proc_status stdout ----
thread '<unnamed>' panicked at src/main.rs:6:40:
error getting proc/self/status pid: Os { code: 95, kind: Uncategorized, message: "Operation not supported" }
thread 'parallel_self_proc_status' panicked at src/main.rs:16:23:
[...]
sunfishcode added a commit that referenced this issue May 17, 2024
Have `open_and_check_file` create a new file descriptor before scanning
for directory entries, so that it doesn't share a directory position
with other threads.

Fixes #1050.
sunfishcode added a commit that referenced this issue May 21, 2024
…ds. (#1059)

* Fix `procfs`'s `open_and_check_file` to work in the presence of threads.

Have `open_and_check_file` create a new file descriptor before scanning
for directory entries, so that it doesn't share a directory position
with other threads.

Fixes #1050.

* Fix build errors on powerpc64-ibm-aix.
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 a pull request may close this issue.

1 participant