fix(core): resolve excessive CPU consumption via child_process.rs (#31110)

<!-- 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` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## 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 #
This commit is contained in:
James Henry 2025-05-07 23:05:16 +04:00 committed by GitHub
parent 68426f6adb
commit 9b2eed2662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
use super::process_killer::ProcessKiller;
use crate::native::pseudo_terminal::pseudo_terminal::{ParserArc, WriterArc};
use crossbeam_channel::Sender;
use crossbeam_channel::{bounded, Receiver};
use crossbeam_channel::{bounded, select, Receiver};
use napi::bindgen_prelude::External;
use napi::{
threadsafe_function::{
@ -92,17 +92,25 @@ impl ChildProcess {
std::thread::spawn(move || {
loop {
if kill_rx.try_recv().is_ok() {
select! {
recv(kill_rx) -> _ => {
break;
}
if let Ok(content) = rx.try_recv() {
},
recv(rx) -> msg => {
match msg {
Ok(content) => {
// windows will add `ESC[6n` to the beginning of the output,
// we dont want to store this ANSI code in cache, because replays will cause issues
// remove it before sending it to js
#[cfg(windows)]
let content = content.replace("\x1B[6n", "");
callback_tsfn.call(content, NonBlocking);
},
Err(_) => {
break;
}
}
}
}
}
});