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>
Collaborator
|
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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