-
Notifications
You must be signed in to change notification settings - Fork 1.4k
More fork safety #7380
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
Merged
Merged
More fork safety #7380
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6217ad6
apply more allow_threads
youknowone 6b6138b
Simplify STW thread state transitions
youknowone 396fec9
Representable for ThreadHandle
youknowone 9fe70f2
Set ThreadHandle state to Running in parent thread after spawn
youknowone e37b15f
Set ThreadHandle state to Running in parent thread after spawn
youknowone cfd7f01
Add debug_assert for thread state in start_the_world
youknowone 1b97419
Unskip now-passing test_get_event_loop_thread and test_start_new_thre…
youknowone 1ba2821
Wrap IO locks and file ops in allow_threads
youknowone ca41577
Use std::sync for thread start/ready events
youknowone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add debug_assert for thread state in start_the_world
- Loading branch information
commit cfd7f011aacfd7b0dcf9f14e4668285bc07699fe
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linux:
/proc/self/statparsing is fragile when comm contains spaces.The
commfield (field 2 in/proc/self/stat) is enclosed in parentheses and can contain spaces, parentheses, or newlines. Usingsplit_whitespace().nth(19)will yield incorrect results if the process name contains spaces.For example, a process named "my app" produces:
split_whitespace()splits this into["123", "(my", "app)", "S", ...], makingnth(19)point to the wrong field.CPython handles this by finding the last
)to locate the end of the comm field, then counting fields from there.🛡️ Suggested fix to handle comm field correctly
#[cfg(target_os = "linux")] { use std::io::Read as _; let mut file = match std::fs::File::open("/proc/self/stat") { Ok(f) => f, Err(_) => return 0, }; let mut buf = [0u8; 160]; let n = match file.read(&mut buf) { Ok(n) => n, Err(_) => return 0, }; let line = match core::str::from_utf8(&buf[..n]) { Ok(s) => s, Err(_) => return 0, }; - if let Some(field) = line.split_whitespace().nth(19) { - return field.parse::<isize>().unwrap_or(0); + // Find end of comm field (last ')') to handle spaces in process name + let after_comm = match line.rfind(')') { + Some(idx) => &line[idx + 1..], + None => return 0, + }; + // Field 20 (num_threads) is the 17th field after comm (fields 3-19 are 17 fields) + if let Some(field) = after_comm.split_whitespace().nth(17) { + return field.parse::<isize>().unwrap_or(0); } 0 }🤖 Prompt for AI Agents