Skip to content

Commit

Permalink
fix(core): retry interrupted errors when writing to stdout (#23359)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 1acbc7e)
  • Loading branch information
AgentEnder authored and FrozenPandaz committed May 15, 2024
1 parent 7ff68e5 commit 4e6a193
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 4e6a193

Please sign in to comment.