Background node process corrupts terminal state with tcsetattr() on exit
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
- Version: v14.9.0
- Platform: NixOS 21.03, Linux 5.8.11 x86_64
- Subsystem:
ResetStdioinsrc/node.cc
In Bash, run the following:
node -e 'setTimeout(() => {}, 2000)' & sleep 1
This launches node -e 'setTimeout(() => {}, 2000)' in the background and sleep 1 in the foreground. After 1 second, control returns to Bash. After 2 seconds, Node exits and corrupts Bash’s terminal state:
- the ↑, ↓, →, ← arrow keys start printing
^[[A,^[[B,^[[C,^[[Dinstead of scrolling through the Bash history or moving the insert point, - the Tab key starts moving the cursor 8 spaces forward instead of Tab-completing the command,
- Ctrl+A and Ctrl+E print
^Aand^Einstead of jumping to the beginning and end of the command, etc.
This happens when the ResetStdio handler uses tcsetattr to “restore” the terminal to the state it was in when Node started (#24260). This interferes with Bash, which uses and expects a different terminal state than sleep 1.
(The bug is sometimes reproducible without the sleep 1 depending on whether Node records the initial terminal state before Bash updates it, but the sleep 1 makes it reliable.)
Normally, the terminal state would be protected from such undesired modifications by a background process: the kernel generates SIGTTOU to suspend the process until it’s brought to the foreground. But ResetStdio now deliberately overrides this protection by blocking SIGTTOU (#28535).
IMO, both #24260 and #28535 should be reverted. Node is a programming language; it should never make changes to the terminal state that programs did not request.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/node.cc 中的 ResetStdio 处理程序开始,使用报告中的 Bash 命令重现该问题。阅读 #24260 和 #28535 中的上下文,包括 SIGTTOU 处理和 tcsetattr 调用。当后台 Node 进程退出且不改变 Bash 的终端行为时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, linux, nodejs
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100