GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: add --no-restore-terminal-state by fatihguzeldev · Pull Request #66540 · nodejs/node

Conversation

@fatihguzeldev

@fatihguzeldev fatihguzeldev commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Restoring startup terminal settings on exit can overwrite changes made
by another process sharing the terminal, such as an interactive pager.

Add --no-restore-terminal-state as a POSIX opt-out while preserving
libuv's terminal mode cleanup and restoration of O_NONBLOCK.
The default behavior is unchanged.

Includes documentation and pseudo-TTY tests covering exit paths,
NODE_OPTIONS, option precedence, and raw-mode cleanup.

Refs: #66440
Refs: #66134

Tested on macOS arm64: release build, focused pseudo-TTY and CLI tests,
raw-mode cleanup, less 710 reproduction, and lint checks passed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

woosal1337 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@fatihguzeldev
src: add --no-restore-terminal-state
464554f
Restoring startup terminal settings on exit can overwrite changes made
by another process sharing the terminal, such as an interactive pager.

Add a POSIX opt-out that preserves libuv's terminal mode cleanup and
restoration of the O_NONBLOCK flag.

Refs: nodejs#66440
Signed-off-by: Fatih Güzel <[email protected]>
@nodejs-github-bot

nodejs-github-bot commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Oct 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.40%. Comparing base (019e869) to head (92f4e11).
⚠️ Report is 143 commits behind head on main.

Files with missing lines Patch % Lines
src/node.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #66540    +/-   ##
========================================
  Coverage   90.40%   90.40%            
========================================
  Files         791      791            
  Lines      276011   276232   +221     
  Branches    52983    53042    +59     
========================================
+ Hits       249529   249731   +202     
- Misses      16891    16894     +3     
- Partials     9591     9607    +16     
Files with missing lines Coverage Δ
src/node_options.cc 81.73% <100.00%> (+0.02%) ⬆️
src/node_options.h 95.67% <100.00%> (+0.01%) ⬆️
src/node.cc 78.87% <75.00%> (-0.05%) ⬇️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avih avih mentioned this pull request Oct 5, 2026
Problem with newer less #66440
Closed
@avih

avih commented Oct 5, 2026

Copy link
Copy Markdown

Thanks for the suggested fix.

While it can help if one knows to manually use this flag and override the default behavior, is there a good reason to perform this reset by default even if no tty fd was used at all from-start-to-finish of this node instance?

After all, when node exits, it already knows (or technically can know) whether something was read-from and/or written-to a tty fd, and surely this reset is never required if such tty fd was not touched at all?

fatihguzeldev reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MikeMcC399

MikeMcC399 commented Oct 6, 2026

Copy link
Copy Markdown
Member

Please make sure you have read and understood the following documents:

  • Guides and FAQs for first-time contributors
  • Contribution and Automation Policies
  • Pull Request Guide
  • AI Use - Policy and Guidelines
  • Code of Conduct
fatihguzeldev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fatihguzeldev
test: fix terminal state restoration test portability
92f4e11
Change and restore only ECHO to avoid GNU stty failures on macOS.
Only run NODE_OPTIONS cases when support is enabled.

Signed-off-by: Fatih Güzel <[email protected]>
@avih

avih commented Oct 6, 2026

Copy link
Copy Markdown

@fatihguzeldev mind responding to my comment in words?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fatihguzeldev

fatihguzeldev commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@avih sorry about that. i pushed the test fix and then fell asleep before writing a reply.

whether something was read-from and/or written-to a tty fd

what about a child process changing the terminal settings through inherited stdio?

require('node:child_process').spawnSync(
  'stty', ['-echo'], { stdio: 'inherit' }
);

the parent node process does no tty reads or writes here, but currently restores "echo" on exit. should node leave "echo" disabled in this case?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avih

avih commented Oct 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

I'd leave it up to you to decide whether you want to discuss these subjects at the bug report - #66440 or here. I think we should continue it there, but I'll post my response here, and let you decide where you want to continue.

I don't think this PR is a bad first step, but ultimately it's an easy "let's add an option" solution which still leaves users affected by this issue by default, and largely completely unaware of why their usecase is broken, and what they might need to do to fix it.

The core issue at #66440 is that a node application which only reads files from disk and prints to stdout - which is a pipe, still resets the terminal state when it exits despite never having any interaction at all with the tty, and this hurts the next element at the pipeline (an interactive pager).

I think there are two questions here:

  1. What is the ideal behavior?
  2. What can we do about it, in the short and long terms?

I think the ideal behavior, especially in cases where there was no interaction whatsoever between the application and the tty, is to not reset the tty state on exit.

Do you agree with that?

It's important to understand what the idea behavior is, because then we can evaluate how near or far specific solutions - like this PR - are from the best solution.

It's entirely possible that this PR is great as a short term solution, but maybe not so great if nothing else is done beyond that.

what about a child process changing the terminal settings through inherited stdio?

First, let me ask you the same question. What if this is what this application does, because it wants to disable echo in the terminal - and leave it like that when it exits, and then node overrides and restores echo? For instance if this application is stty.js which is an application which changes the terminal settings?

I'd think that in this case it's the responsibility of the application (not node) to restore it, because this application knowingly changed the terminal settings.

Applications shouldn't just disable the terminal echo and then exit without restoring it (unless that's what they're designed to do). This is not the responsibility of node to restore the state in this case.

Now, I'm not familiar with the node docs, but if it says something like "node will reset the terminal state on exit, so an application can do any changes it wants, and it's guaranteed to be restored automatically when it exits", then it besomes harder to change it.

Not impossible, but harder.

But if node doesn't make such guarantee, then it's the responsibility of the application to restore whatever it changed.

It's obvious that there are a lot of cases to consider here, and I don't know the most important thing - why it resets the terminal on exit to begin with.

Is it by design? if yes, why? Is it to restore things which the application changes (like your stty example)? to restore things which node itself changes? some other reasons?

Or maybe it's just a bug, and no one actually intended to reset it on exit, so we could just remove it?

Or maybe it's by design, but the design didn't take into account that sometimes this reset can be harmful? Like when piping into a pager, or when breaking applications like our stty.js?

Once we can answer this main question of "why", then it should be easier to find a good solution.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MikeMcC399
MikeMcC399 requested a review from avivkeller October 6, 2026 12:59
@fatihguzeldev

fatihguzeldev commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@avih yes, i agree. users shouldn't need to know about a flag for this to work. i went with the opt-out after seeing a similar proposal, but it doesn't fix the default behavior.

i agree about stty too. the application should handle its own intentional changes.

let's continue in #66440. i looked into why restoration was added and will share what i found there.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MikeMcC399
MikeMcC399 removed the request for review from avivkeller October 8, 2026 09:38
@MikeMcC399

MikeMcC399 commented Oct 8, 2026

Copy link
Copy Markdown
Member

Since there is an on-going discussion in #66440 I would suggest to close this PR and focus on the issue until such time as consensus has been reached.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MikeMcC399

MikeMcC399 commented Oct 8, 2026

Copy link
Copy Markdown
Member

If your PR is intended to fix an issue, then include the Fixes: prefix in the PR description.

See Commit message guidelines according to the Pull requests documentation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@avih avih mentioned this pull request Oct 8, 2026
node 10.2.0+ turning off stty echo when using process.stdin.setRawMode() #21020
Closed
@fatihguzeldev fatihguzeldev mentioned this pull request Oct 11, 2026
Background node process corrupts terminal state with tcsetattr() on exit #35536
Open
@mcollina mcollina added the semver-minor PRs that contain new features and should be released in the next minor version. label Oct 15, 2026
@mcollina mcollina mentioned this pull request Oct 15, 2026
src: restore tty state on exit only if changed #66753
Merged
nodejs-github-bot pushed a commit that referenced this pull request Nov 13, 2026
@mcollina
src: restore tty state on exit only if changed
726d4d4
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: #66440
Refs: #35536
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #66753
Refs: #66540
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
@fatihguzeldev fatihguzeldev closed this Nov 18, 2026
aduh95 pushed a commit that referenced this pull request Nov 19, 2026
@mcollina @aduh95
src: restore tty state on exit only if changed
a6fc41c
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: #66440
Refs: #35536
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #66753
Refs: #66540
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@mcollina @gabylb
src: restore tty state on exit only if changed
2ad3d0a
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 <[email protected]>
PR-URL: nodejs#66753
Refs: nodejs#66540
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@fatihguzeldev @nodejs-github-bot @avih @MikeMcC399 @mcollina
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.