From a947c6fbf7c71544687c79716eadbffe4bdedc82 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 29 May 2024 09:53:04 -0700 Subject: fix(ext/node): windows cancel stdin read in line mode (#23969) This patch fixes stdin read hanging on user input when switching tty mode on Windows Fixes #21111 On Windows, when switching from line to raw mode: - Cancel ongoing console read by writing a return keypress to its input buffer. This blocks the main thread until any ongoing read has been cancelled to prevent interference with the screen state. - On the read thread, restore the cursor position to where it was before writing the enter, undoing its effect on the screen state. - Restart reading and notify the main thread. --- tests/integration/run_tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 91370a87c..f7aaa9daf 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -3141,6 +3141,20 @@ itest!(byte_order_mark { output: "run/byte_order_mark.out", }); +#[test] +#[cfg(windows)] +fn process_stdin_read_unblock() { + TestContext::default() + .new_command() + .args_vec(["run", "run/process_stdin_unblock.mjs"]) + .with_pty(|mut console| { + console.write_raw("b"); + console.human_delay(); + console.write_line_raw("s"); + console.expect_all(&["1", "1"]); + }); +} + #[test] fn issue9750() { TestContext::default() -- cgit v1.2.3