Skip to content

Commit 587659c

Browse files
fix(core): move tui to parking lot rwlock to avoid hang (#34187)
## Current Behavior There's a hard to reproduce hang that happens occasionally when running the TUI ## Expected Behavior We think this should fix it ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
1 parent 05de3ff commit 587659c

3 files changed

Lines changed: 95 additions & 149 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use napi::{
99
ErrorStrategy::Fatal, ThreadsafeFunction, ThreadsafeFunctionCallMode::NonBlocking,
1010
},
1111
};
12-
use parking_lot::Mutex;
12+
use parking_lot::{Mutex, RwLock};
1313
use std::io::Write;
14-
use std::sync::{Arc, RwLock};
14+
use std::sync::Arc;
1515
use tracing::warn;
1616
use vt100_ctt::Parser;
1717

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use crossterm::{
66
tty::IsTty,
77
};
88
use napi::bindgen_prelude::*;
9-
use parking_lot::Mutex;
9+
use parking_lot::{Mutex, RwLock};
1010
use portable_pty::{CommandBuilder, NativePtySystem, PtyPair, PtySize, PtySystem};
1111
use std::io::stdout;
12-
use std::sync::RwLock;
1312
use std::{
1413
collections::HashMap,
1514
io::{Read, Write},
@@ -111,14 +110,8 @@ impl PseudoTerminal {
111110
trace!("Quiet: {}", quiet);
112111
debug!("Read {} bytes", len);
113112
if is_within_nx_tui {
114-
if let Ok(mut parser) = parser_clone.write() {
115-
if is_within_nx_tui {
116-
trace!("Processing data via vt100 for use in tui");
117-
parser.process(&buf[..len]);
118-
}
119-
} else {
120-
debug!("Failed to lock parser");
121-
}
113+
trace!("Processing data via vt100 for use in tui");
114+
parser_clone.write().process(&buf[..len]);
122115
}
123116

124117
if !quiet {
@@ -213,10 +206,7 @@ impl PseudoTerminal {
213206

214207
if self.is_within_nx_tui {
215208
// within the tui, update the parser directly so it is displayed in the tui
216-
self.parser
217-
.write()
218-
.expect("Failed to acquire parser write lock")
219-
.process(command_info.as_bytes());
209+
self.parser.write().process(command_info.as_bytes());
220210
} else if !quiet {
221211
// outside the tui, just print to stdout so the user can see it
222212
if let Err(e) = std::io::stdout().write_all(command_info.as_bytes()) {

0 commit comments

Comments
 (0)