fix: client stdout race (#5693)

This commit is contained in:
Aram Drevekenin
2026-10-08 10:35:02 +02:00
committed by GitHub
parent b24a7a1e3e
commit 328be6919c
+28 -21
View File
@@ -1424,7 +1424,7 @@ pub fn start_client(
let handle_error = |backtrace: String| {
os_input.disable_mouse().non_fatal();
os_input.unset_raw_mode().unwrap();
let _ = os_input.unset_raw_mode();
os_input.restore_console_mode();
let error = terminal_teardown_message(
&backtrace,
@@ -1432,8 +1432,8 @@ pub fn start_client(
!explicitly_disable_kitty_keyboard_protocol,
);
let mut stdout = os_input.get_stdout_writer();
stdout.write_all(error.as_bytes()).unwrap();
stdout.flush().unwrap();
let _ = stdout.write_all(error.as_bytes());
let _ = stdout.flush();
std::process::exit(1);
};
@@ -1465,20 +1465,12 @@ pub fn start_client(
},
ClientInstruction::Render(output) => {
let mut stdout = os_input.get_stdout_writer();
if let Some(sync) = synchronised_output {
stdout
.write_all(sync.start_seq())
.expect("cannot write to stdout");
if let Err(e) = write_render_output(&mut *stdout, &output, synchronised_output) {
let message = format!("Failed to write to the terminal: {}", e);
log::error!("{}", message);
os_input.send_to_server(ClientToServerMsg::ClientExited);
handle_error(message);
}
stdout
.write_all(output.as_bytes())
.expect("cannot write to stdout");
if let Some(sync) = synchronised_output {
stdout
.write_all(sync.end_seq())
.expect("cannot write to stdout");
}
stdout.flush().expect("could not flush");
},
ClientInstruction::UnblockInputThread => {
command_is_executing.unblock_input_thread();
@@ -1661,16 +1653,16 @@ pub fn start_client(
os_input.disable_mouse().non_fatal();
info!("{}", exit_msg);
os_input.unset_raw_mode().unwrap();
let _ = os_input.unset_raw_mode();
os_input.restore_console_mode();
let mut stdout = os_input.get_stdout_writer();
stdout.write_all(goodbye_message.as_bytes()).unwrap();
stdout.flush().unwrap();
let _ = stdout.write_all(goodbye_message.as_bytes());
let _ = stdout.flush();
} else {
let clear_screen = "\u{1b}[2J";
let mut stdout = os_input.get_stdout_writer();
stdout.write_all(clear_screen.as_bytes()).unwrap();
stdout.flush().unwrap();
let _ = stdout.write_all(clear_screen.as_bytes());
let _ = stdout.flush();
}
let _ = send_input_instructions.send(InputInstruction::Exit);
@@ -1804,6 +1796,21 @@ pub fn start_server_detached(
os_input.send_to_server(first_msg);
}
fn write_render_output(
stdout: &mut dyn Write,
output: &str,
synchronised_output: Option<SyncOutput>,
) -> std::io::Result<()> {
if let Some(sync) = synchronised_output {
stdout.write_all(sync.start_seq())?;
}
stdout.write_all(output.as_bytes())?;
if let Some(sync) = synchronised_output {
stdout.write_all(sync.end_seq())?;
}
stdout.flush()
}
fn terminal_teardown_message(message: &str, rows: usize, include_kitty_exit: bool) -> String {
let goto_start_of_last_line = format!("\u{1b}[{};{}H", rows, 1);
let kitty_exit = if include_kitty_exit {