fix: race on rx subscription (#7921)
Fix race where the PTY was sending first chunk before the subscription to the broadcast
This commit is contained in:
parent
b99ce883fe
commit
f152b16ed9
1 changed files with 4 additions and 1 deletions
|
|
@ -54,6 +54,7 @@ impl ExecCommandSession {
|
|||
pub fn new(
|
||||
writer_tx: mpsc::Sender<Vec<u8>>,
|
||||
output_tx: broadcast::Sender<Vec<u8>>,
|
||||
initial_output_rx: broadcast::Receiver<Vec<u8>>,
|
||||
killer: Box<dyn portable_pty::ChildKiller + Send + Sync>,
|
||||
reader_handle: JoinHandle<()>,
|
||||
writer_handle: JoinHandle<()>,
|
||||
|
|
@ -62,7 +63,6 @@ impl ExecCommandSession {
|
|||
exit_code: Arc<StdMutex<Option<i32>>>,
|
||||
pair: PtyPairWrapper,
|
||||
) -> (Self, broadcast::Receiver<Vec<u8>>) {
|
||||
let initial_output_rx = output_tx.subscribe();
|
||||
(
|
||||
Self {
|
||||
writer_tx,
|
||||
|
|
@ -177,6 +177,8 @@ pub async fn spawn_pty_process(
|
|||
|
||||
let (writer_tx, mut writer_rx) = mpsc::channel::<Vec<u8>>(128);
|
||||
let (output_tx, _) = broadcast::channel::<Vec<u8>>(256);
|
||||
// Subscribe before starting the reader thread.
|
||||
let initial_output_rx = output_tx.subscribe();
|
||||
|
||||
let mut reader = pair.master.try_clone_reader()?;
|
||||
let output_tx_clone = output_tx.clone();
|
||||
|
|
@ -242,6 +244,7 @@ pub async fn spawn_pty_process(
|
|||
let (session, output_rx) = ExecCommandSession::new(
|
||||
writer_tx,
|
||||
output_tx,
|
||||
initial_output_rx,
|
||||
killer,
|
||||
reader_handle,
|
||||
writer_handle,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue