-
Notifications
You must be signed in to change notification settings - Fork 14
Ignore forked but not exec'd child processes #1302
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
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,10 +3,7 @@ mod memory; | |||||
| mod stat; | ||||||
| mod uptime; | ||||||
|
|
||||||
| use std::{ | ||||||
| collections::{VecDeque, hash_map::Entry}, | ||||||
| io, | ||||||
| }; | ||||||
| use std::{collections::VecDeque, io}; | ||||||
|
|
||||||
| use metrics::gauge; | ||||||
| use nix::errno::Errno; | ||||||
|
|
@@ -87,13 +84,36 @@ impl Sampler { | |||||
| let mut processes_found: i32 = 0; | ||||||
| let mut pids_skipped: FxHashSet<i32> = FxHashSet::default(); | ||||||
|
|
||||||
| // Clear process_info at the start of each poll. A process is capable of | ||||||
| // changing its details in key ways between polls. | ||||||
| self.process_info.clear(); | ||||||
|
|
||||||
| // Every sample run we collect all the child processes rooted at the | ||||||
| // parent. As noted by the procfs documentation is this done by | ||||||
| // dereferencing the `/proc/<pid>/root` symlink. | ||||||
| let mut pids: FxHashSet<i32> = FxHashSet::default(); | ||||||
| // We must be sure to initialize the parent process info. | ||||||
| let parent_pid = self.parent.pid(); | ||||||
| let parent_info = match initialize_process_info(parent_pid).await { | ||||||
| Ok(Some(info)) => info, | ||||||
| Ok(None) => { | ||||||
| warn!("Could not initialize parent process info"); | ||||||
| return Ok(()); | ||||||
| } | ||||||
| Err(e) => { | ||||||
| warn!("Error initializing parent process info: {:?}", e); | ||||||
| return Ok(()); | ||||||
| } | ||||||
| }; | ||||||
| self.process_info.insert(parent_pid, parent_info); | ||||||
|
|
||||||
| let mut processes: VecDeque<Process> = VecDeque::with_capacity(16); // an arbitrary smallish number | ||||||
| processes.push_back(Process::new(self.parent.pid())?); | ||||||
| pids.insert(self.parent.pid()); | ||||||
| processes.push_back(Process::new(parent_pid)?); | ||||||
|
|
||||||
| // We need to track the pids of processes we've already seen to avoid | ||||||
| // duplicate reads of process info. A child pid may be listed multiple | ||||||
| // times, see below loop for details. | ||||||
| let mut pids: FxHashSet<i32> = FxHashSet::default(); | ||||||
| pids.insert(parent_pid); | ||||||
|
|
||||||
| while let Some(process) = processes.pop_back() { | ||||||
| // Search for child processes. This is done by querying for every | ||||||
|
|
@@ -102,6 +122,11 @@ impl Sampler { | |||||
| // id equal to their pid. It's also possible for a pid to list | ||||||
| // itself as a child so we reference the pid hashset above to avoid | ||||||
| // infinite loops. | ||||||
| // | ||||||
| // We take special care to avoid processes that are forked but not | ||||||
| // exec'd. We do this because unexeced processes register the heap | ||||||
| // memory of the parent process in their smaps, leading to a double | ||||||
| // counting. | ||||||
| if let Ok(tasks) = process.tasks() { | ||||||
| for task in tasks.flatten() { | ||||||
| if let Ok(mut children) = task.children() { | ||||||
|
|
@@ -111,9 +136,37 @@ impl Sampler { | |||||
| { | ||||||
| let pid = child.pid(); | ||||||
| if !pids.contains(&pid) { | ||||||
| // We have not seen this process and do need to | ||||||
| // record it for child scanning and sampling if | ||||||
| // it proves to be a process. | ||||||
| // This is a new process. We initialize its | ||||||
| // process info and then determine by | ||||||
| // examination of the exe/cmdline if the process | ||||||
| // is not exec'd -- meaning we will not poll it | ||||||
|
||||||
| // is not exec'd -- meaning we will not poll it | |
| // is fork'd but not exec'd -- meaning we will not poll it |
Oops, something went wrong.
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.
I was going back and forth on whether this is fatal or not, and I agree that this is fine to return
Ok, if we return anErr, then the observer server will crash and this will never retry, which is not the behavior we want. This is a retry-able error.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.
To your point, this is an error and not a warning.
Technically
ladingrecovers but an error has happened that results in unexpected results.