nodejs / nodejs/node

Node doesn't reset tty on early/aborted exit

Open
#41,143 17 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tty
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v16.13.1, v17.2.0 tested

Platform

Linux lux0 5.11.22-100.fc32.x86_64 #1 SMP Wed May 19 18:58:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Create this script file in test.js:

#!/usr/bin/env node
for (let i = 0; i < 100000; i++) {
console.log("i:", i)
}

In a shell window, run:

test.js |less

Hit "q" to quit less (after only one page of output), which also kills test.js while it still has undelivered data in the stdout buffer.

Your tty will be left in raw mode (no echo, other command characters disabled). Must do a "stty sane" to restore usability of the console.

How often does it reproduce? Is there a required condition?

Happens every time. Have tested multiple versions of node on Linux and MacOS.

What is the expected behavior?

Should restore my tty settings no matter how ugly the exit conditions.

What do you see instead?

Tty is left in raw mode with no echo. Can't see my typed commands.

Additional information

Is there a standard way of dealing with this in case a script is killed before it can write its output? Or is this a bug in node?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the test.js script and test.js | less, then inspect Node.js handling of terminal state during aborted or early process exit. Add regression coverage for quitting less while output remains buffered, and verify that the tty returns to normal without requiring stty sane.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.