Skip to content

Commit

Permalink
fix: dedicated thread for parent process checker (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Feb 23, 2024
1 parent 60ad5f0 commit 2976954
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/core/src/plugins/process/parent_process_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ use std::time::Duration;
/// Note: This must be called from a tokio runtime.
pub fn start_parent_process_checker_task(parent_process_id: u32) {
crate::async_runtime::spawn(async move {
loop {
tokio::time::sleep(Duration::from_secs(10)).await;
// wait cheaply for 2 seconds
tokio::time::sleep(Duration::from_secs(2)).await;

// now spawn a dedicated thread that will keep checking this
// in case the tokio runtime gets blocked. Also, DO NOT
// use spawn_blocking from tokio here because it will keep
// the process alive
std::thread::spawn(move || loop {
std::thread::sleep(Duration::from_secs(5));
if !is_process_active(parent_process_id) {
std::process::exit(1);
}
}
});
});
}

Expand Down

0 comments on commit 2976954

Please sign in to comment.