Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(watch): ensure TUI is shutdown regardless of exit path #9408

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,10 @@ pub async fn run(
let base = CommandBase::new(cli_args, repo_root, version, color_config);

let mut client = WatchClient::new(base, event).await?;
client.start().await?;
if let Err(e) = client.start().await {
client.shutdown().await;
return Err(e.into());
}
// We only exit if we get a signal, so we return a non-zero exit code
return Ok(1);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/process/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl Child {
// On Windows it is important that this gets dropped once the child process
// exits
let controller = controller;
debug!("waiting for task");
debug!("waiting for task: {pid:?}");
let manager = ChildStateManager {
shutdown_style,
task_state,
Expand Down
21 changes: 14 additions & 7 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,6 @@ impl WatchClient {
biased;
_ = signal_subscriber.listen() => {
tracing::info!("shutting down");
if let Some(RunHandle { stopper, run_task }) = self.persistent_tasks_handle.take() {
// Shut down the tasks for the run
stopper.stop().await;
// Run should exit shortly after we stop all child tasks, wait for it to finish
// to ensure all messages are flushed.
let _ = run_task.await;
}
Err(Error::SignalInterrupt)
}
result = event_fut => {
Expand Down Expand Up @@ -267,6 +260,20 @@ impl WatchClient {
Ok(())
}

/// Shut down any resources that run as part of watch.
pub async fn shutdown(&mut self) {
if let Some(sender) = &self.ui_sender {
sender.stop().await;
}
if let Some(RunHandle { stopper, run_task }) = self.persistent_tasks_handle.take() {
// Shut down the tasks for the run
stopper.stop().await;
// Run should exit shortly after we stop all child tasks, wait for it to finish
// to ensure all messages are flushed.
let _ = run_task.await;
}
}

/// Executes a run with the given changed packages. Splits the run into two
/// parts:
/// 1. The persistent tasks that are not allowed to be interrupted
Expand Down
Loading