Skip to content

Commit

Permalink
fix(core): retry interrupted errors when writing to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 14, 2024
1 parent cfadd7d commit cfadc47
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn create_pseudo_terminal() -> napi::Result<PseudoTerminal> {
let mut stdout = std::io::stdout();
let mut buf = [0; 8 * 1024];

loop {
'read_loop: loop {
if let Ok(len) = reader.read(&mut buf) {
if len == 0 {
break;
Expand All @@ -87,17 +87,32 @@ pub fn create_pseudo_terminal() -> napi::Result<PseudoTerminal> {
trace!("Prevented terminal escape sequence ESC[6n from being printed.");
content = content.replace("\x1B[6n", "");
}
if stdout.write_all(content.as_bytes()).is_err() {
break;
} else {
let _ = stdout.flush();
let mut logged_interrupted_error = false;
while let Err(e) = stdout.write_all(content.as_bytes()) {
match e.kind() {
std::io::ErrorKind::Interrupted => {
if !logged_interrupted_error {
trace!("Interrupted error writing to stdout: {:?}", e);
logged_interrupted_error = true;
}
continue;
}
_ => {
// We should figure out what to do for more error types as they appear.
trace!("Error writing to stdout: {:?}", e);
trace!("Error kind: {:?}", e.kind());
break 'read_loop;
}
}
}
let _ = stdout.flush();
}
}
if !running_clone.load(Ordering::SeqCst) {
printing_tx.send(()).ok();
}
}

printing_tx.send(()).ok();
});
if std::io::stdout().is_tty() {
Expand Down

0 comments on commit cfadc47

Please sign in to comment.