Skip to content

Commit

Permalink
Improve handling of deleted executable object files (#65)
Browse files Browse the repository at this point in the history
As before this commit, if lightswitch finds an object file that's been
deleted, which are named as `$original_name (deleted)` we would return
an error and never add the unwind information for any of the object
files. We could see this for example in lightswitch as I assume some
parts of the runtime could load the debuginfo file at runtime and then
remove it at some point.

This commit also slighly improves the code/

Test Plan
=========

Ran while running another `lightswitch` instance, the error is not
showing up anymore.
  • Loading branch information
javierhonduco authored Sep 6, 2024
1 parent 4e4a190 commit 6c5cec2
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,13 +1261,33 @@ impl Profiler<'_> {
abs_path.push("/root");
abs_path.push(path);

let file = fs::File::open(&abs_path)?;
let object_file = ObjectFile::new(&abs_path);
if object_file.is_err() {
warn!("object_file failed with {:?} {:?}", object_file, abs_path);
// We've seen debug info executables that get deleted in Rust applications.
// There are probably other cases, but we'll handle them as we bump into them.
if abs_path.to_str().unwrap().contains("(deleted)") {
continue;
}
let object_file = object_file.unwrap();

// We want to open the file as quickly as possible to minimise the chances of races
// if the file is deleted.
let file = match fs::File::open(&abs_path) {
Ok(f) => f,
Err(e) => {
warn!("failed to open file {} due to {:?}", abs_path.display(), e);
// Rather than returning here, we prefer to be able to profile some
// parts of the binary
continue;
}
};

let object_file = match ObjectFile::new(&abs_path) {
Ok(f) => f,
Err(e) => {
warn!("object_file {} failed with {:?}", abs_path.display(), e);
// Rather than returning here, we prefer to be able to profile some
// parts of the binary
continue;
}
};

// Disable profiling Go applications as they are not properly supported yet.
// Among other things, blazesym doesn't support symbolizing Go binaries.
Expand Down

0 comments on commit 6c5cec2

Please sign in to comment.