Skip to content

Commit

Permalink
ChildProcessSupervisor: Check termination before child exit
Browse files Browse the repository at this point in the history
This leads to a faster shutdown in case of CTRL+C.
  • Loading branch information
jherbel committed Oct 10, 2023
1 parent fff8eca commit 70ea89e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions v2/rust/src/child_process_supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ impl ChildProcessSupervisor<'_> {

async fn wait_for_child_exit(self, child: &mut Child) -> Result<ChildProcessOutcome> {
loop {
if self.termination_flag.should_terminate() {
kill_process_tree(child);
bail!("Terminated")
}

if let Some(exit_status) = child
.try_wait()
.context(format!(
Expand All @@ -47,10 +52,6 @@ impl ChildProcessSupervisor<'_> {
return Ok(ChildProcessOutcome::Exited(exit_status));
}

if self.termination_flag.should_terminate() {
kill_process_tree(child);
bail!("Terminated")
}
sleep(Duration::from_millis(250)).await
}
}
Expand Down

0 comments on commit 70ea89e

Please sign in to comment.