Skip to content

Commit 4e6a193

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): retry interrupted errors when writing to stdout (#23359)
<!-- 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)
1 parent 7ff68e5 commit 4e6a193

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn create_pseudo_terminal() -> napi::Result<PseudoTerminal> {
7171
let mut stdout = std::io::stdout();
7272
let mut buf = [0; 8 * 1024];
7373

74-
loop {
74+
'read_loop: loop {
7575
if let Ok(len) = reader.read(&mut buf) {
7676
if len == 0 {
7777
break;
@@ -87,17 +87,32 @@ pub fn create_pseudo_terminal() -> napi::Result<PseudoTerminal> {
8787
trace!("Prevented terminal escape sequence ESC[6n from being printed.");
8888
content = content.replace("\x1B[6n", "");
8989
}
90-
if stdout.write_all(content.as_bytes()).is_err() {
91-
break;
92-
} else {
93-
let _ = stdout.flush();
90+
let mut logged_interrupted_error = false;
91+
while let Err(e) = stdout.write_all(content.as_bytes()) {
92+
match e.kind() {
93+
std::io::ErrorKind::Interrupted => {
94+
if !logged_interrupted_error {
95+
trace!("Interrupted error writing to stdout: {:?}", e);
96+
logged_interrupted_error = true;
97+
}
98+
continue;
99+
}
100+
_ => {
101+
// We should figure out what to do for more error types as they appear.
102+
trace!("Error writing to stdout: {:?}", e);
103+
trace!("Error kind: {:?}", e.kind());
104+
break 'read_loop;
105+
}
106+
}
94107
}
108+
let _ = stdout.flush();
95109
}
96110
}
97111
if !running_clone.load(Ordering::SeqCst) {
98112
printing_tx.send(()).ok();
99113
}
100114
}
115+
101116
printing_tx.send(()).ok();
102117
});
103118
if std::io::stdout().is_tty() {

0 commit comments

Comments
 (0)