Skip to content

Commit 363caf8

Browse files
fix: keep stdin open for persistent tasks (#7196)
### Description Fixes #7181 Some tools when they are connected to a TTY will take stdin being closed as a sign that they should shut down. This PR changes our behavior to keep stdin open for persistent tasks to avoid premature shutdowns. <img width="649" alt="Screenshot 2024-01-31 at 10 13 00 AM" src="https://github.com/vercel/turbo/assets/4131117/e7c26b16-2813-428b-9fe3-6eb552d2f102"> ### Testing Instructions Verify that using `vite` no longer immediately exits when invoked using a pseudoterminal. <img width="377" alt="Screenshot 2024-01-31 at 10 12 29 AM" src="https://github.com/vercel/turbo/assets/4131117/8a7f42d3-8a52-489a-9459-b6d711799512"> (`vite` outputs a clear screen sequence resulting in the run prelude being erased) Closes TURBO-2208
1 parent 01de08b commit 363caf8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/turborepo-lib/src/task_graph/visitor.rs

+12
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,14 @@ impl<'a> Visitor<'a> {
247247

248248
let workspace_directory = self.repo_root.resolve(workspace_info.package_path());
249249

250+
let persistent = task_definition.persistent;
250251
let mut exec_context = factory.exec_context(
251252
info.clone(),
252253
task_hash,
253254
task_cache,
254255
workspace_directory,
255256
execution_env,
257+
persistent,
256258
);
257259

258260
let output_client = self.output_client(&info);
@@ -563,6 +565,7 @@ impl<'a> ExecContextFactory<'a> {
563565
task_cache: TaskCache,
564566
workspace_directory: AbsoluteSystemPathBuf,
565567
execution_env: EnvironmentVariableMap,
568+
persistent: bool,
566569
) -> ExecContext {
567570
let task_id_for_display = self.visitor.display_task_id(&task_id);
568571
let pass_through_args = self.visitor.run_opts.args_for_task(&task_id);
@@ -586,6 +589,7 @@ impl<'a> ExecContextFactory<'a> {
586589
continue_on_error: self.visitor.run_opts.continue_on_error,
587590
pass_through_args,
588591
errors: self.errors.clone(),
592+
persistent,
589593
}
590594
}
591595

@@ -619,6 +623,7 @@ struct ExecContext {
619623
continue_on_error: bool,
620624
pass_through_args: Option<Vec<String>>,
621625
errors: Arc<Mutex<Vec<TaskError>>>,
626+
persistent: bool,
622627
}
623628

624629
enum ExecOutcome {
@@ -784,6 +789,13 @@ impl ExecContext {
784789
// Always last to make sure it overwrites any user configured env var.
785790
cmd.env("TURBO_HASH", &self.task_hash);
786791

792+
// Many persistent tasks if started hooked up to a pseudoterminal
793+
// will shut down if stdin is closed, so we open it even if we don't pass
794+
// anything to it.
795+
if self.persistent {
796+
cmd.open_stdin();
797+
}
798+
787799
let mut stdout_writer = match self
788800
.task_cache
789801
.output_writer(self.pretty_prefix.clone(), output_client.stdout())

0 commit comments

Comments
 (0)