Skip to content

Commit

Permalink
fix(windows): keep stdin open for conpty processes (#8885)
Browse files Browse the repository at this point in the history
### Description

I forgot that ConPTY behaves differently than Linux-style
psuedoterminals. If `stdin` is closed on a process hooked up to a
ConPTY, then the process will immediately end.

### Testing Instructions

Cut a canary and test it on a Windows machine.
  • Loading branch information
chris-olszewski authored Jul 30, 2024
1 parent 68bbb1f commit e27857d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions crates/turborepo-lib/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ impl ProcessManager {
let use_pty = !cfg!(windows) && atty::is(atty::Stream::Stdout);
Self::new(use_pty)
}

/// Returns whether children will be spawned attached to a pseudoterminal
pub fn use_pty(&self) -> bool {
self.use_pty
}

/// Returns whether or not closing a child's stdin will result in it
/// immediately exiting.
pub fn closing_stdin_ends_process(&self) -> bool {
// Processes spawned hooked up to ConPTY on Windows will immediately exit
// if their stdin is closed. We avoid closing stdin in this case.
cfg!(windows) && self.use_pty
}
}

impl ProcessManager {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ impl ExecContext {
// Even if user does not have the TUI and cannot interact with a task, we keep
// stdin open for persistent tasks as some programs will shut down if stdin is
// closed.
if !self.takes_input {
if !self.takes_input && !self.manager.closing_stdin_ends_process() {
process.stdin();
}

Expand Down

0 comments on commit e27857d

Please sign in to comment.