Skip to content

Commit 85925cd

Browse files
committed
fix(samply): spawn in new thread to prevent tokio panic
1 parent 08f1d96 commit 85925cd

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

src/cli/samply.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ pub fn run(args: SamplyArgs) -> Result<()> {
1616
let argv = std::iter::once(std::ffi::OsString::from("samply")).chain(args.args);
1717
let opt = cli::Opt::parse_from(argv);
1818

19-
match opt.action {
20-
#[cfg(any(
21-
target_os = "android",
22-
target_os = "macos",
23-
target_os = "linux",
24-
target_os = "windows"
25-
))]
26-
cli::Action::Record(a) => ::samply::do_record_action(a),
27-
_ => unimplemented!("Only `samply record` is supported"),
28-
}
19+
// samply spins up its own tokio runtime internally, so it must run on a
20+
// thread that isn't already inside our `#[tokio::main]` runtime.
21+
std::thread::scope(|s| {
22+
s.spawn(|| match opt.action {
23+
#[cfg(any(
24+
target_os = "android",
25+
target_os = "macos",
26+
target_os = "linux",
27+
target_os = "windows"
28+
))]
29+
cli::Action::Record(a) => ::samply::do_record_action(a),
30+
_ => unimplemented!("Only `samply record` is supported"),
31+
})
32+
.join()
33+
.map_err(|_| anyhow::anyhow!("samply thread panicked"))
34+
})?;
2935

3036
Ok(())
3137
}

0 commit comments

Comments
 (0)