Repository navigation
Conversation
ResetStdio() unconditionally writes the terminal attributes recorded at startup back to stdin and stderr when the process exits, even when the process never touched the terminal. This clobbers changes made in the meantime by another process sharing the terminal: in `node -h | less`, less switches the terminal to raw mode once it receives the first byte of output, and node switches it back to cooked mode when it exits. Only restore the recorded attributes when node itself changed the terminal mode through setRawMode(), or when exiting because of a signal. Restoring the O_NONBLOCK flag and libuv's own terminal mode reset are unchanged. Fixes: nodejs#66440 Refs: nodejs#35536 Signed-off-by: Matteo Collina <hello@matteocollina.com>
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66753 +/- ##
==========================================
+ Coverage 90.47% 90.49% +0.02%
==========================================
Files 791 797 +6
Lines 277245 277501 +256
Branches 53310 53324 +14
==========================================
+ Hits 250834 251126 +292
+ Misses 16811 16796 -15
+ Partials 9600 9579 -21
🚀 New features to boost your workflow:
|
|
i checked the completed raw-mode case on macos ( process.stdin.setRawMode(true);
process.stdin.setRawMode(false);another process then changed ECHO/ICANON while node was still running. those changes were overwritten when node exited. i also tried this matches the unpatched build. is keeping the startup fallback enabled after a completed raw-mode session an intentional compatibility choice here? |
ResetStdio()unconditionally writes the terminal attributes recorded at startup back to stdin and stderr when the process exits, even when the process never touched the terminal. This clobbers changes made in the meantime by another process sharing the terminal. Innode -h | less, less switches the terminal to raw mode once it receives the first byte of output, and node switches it back to cooked mode when it exits, so less ends up running with the terminal in cooked mode (see gwsw/less#834). The same mechanism is behind #35536 (backgrounded node process corrupting the shell's terminal state).With this change the recorded attributes are only written back when node itself changed the terminal mode through
setRawMode(), or when exiting because of a signal (SIGINT/SIGTERM, trap handler, watchdog timeout). The fail-safe from #24260 is therefore preserved for every program that asked node to change the terminal, including thesetRawMode(true); process.stdin.destroy()case where libuv alone cannot reset the mode. Restoring theO_NONBLOCKflag and libuv's ownuv_tty_reset_mode()are unchanged.Verified with strace under a pty:
node -e 'console.log(1)' | catissues notcsetattr()on exit anymore, and a consumer that enters raw mode after the first byte of output (like less 710) keeps raw mode after node exits. Alltest/pseudo-ttytests pass. The new test fails on the unpatched binary.The behaviour change is for code that alters the terminal behind libuv's back (native addons,
sttychild processes with inherited stdio) and then exits normally without cleaning up: node no longer papers over that. Marking as semver-major for that reason.Fixes: #66440
Refs: #35536
Refs: #66540
AI generated, reviewed by me