Skip to content

Commit

Permalink
Merge pull request #148 from pythonspeed/147-panic-cgroups
Browse files Browse the repository at this point in the history
Catch errors in memory_stat()
  • Loading branch information
itamarst authored Apr 1, 2021
2 parents aedb4b1 + 37c25d4 commit dd9ccb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .changelog/147.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fil no longer blows up if checking cgroup memory is not possible.
23 changes: 19 additions & 4 deletions memapi/src/oom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,29 @@ impl RealMemoryInfo {
let cgroup_paths = get_cgroup_paths(&contents);
for path in cgroup_paths {
let h = cgroups_rs::hierarchies::auto();
return Some(cgroups_rs::Cgroup::load(h, path));
let cgroup = cgroups_rs::Cgroup::load(h, path);
// Make sure memory_stat() works. Sometimes it doesn't
// (https://github.com/pythonspeed/filprofiler/issues/147). If
// it doesn't, this'll panic.
let mem: &cgroups_rs::memory::MemController = cgroup.controller_of().unwrap();
let _mem = mem.memory_stat();
return Some(cgroup);
}
None
};
return Self {
cgroup: get_cgroup(),
process: psutil::process::Process::current().unwrap(),
let cgroup_result = std::panic::catch_unwind(get_cgroup);
let cgroup = match cgroup_result {
Ok(c) => c,
Err(err) => {
eprintln!(
"=fil-profile= Error retrieving cgroup memory, per-container/per-cgroup memory limits won't be respected (error: {:?}). This is expected behavior on old versions of Linux, e.g. RHEL 7. If you're on a newer version, please file a bug at https://github.com/pythonspeed/filprofiler/issues/new/choose.", err);
None
}
};
Self {
cgroup: cgroup,
process: psutil::process::Process::current().unwrap(),
}
}

#[cfg(target_os = "macos")]
Expand Down

0 comments on commit dd9ccb1

Please sign in to comment.