Background node process corrupts terminal state with tcsetattr() on exit
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
- 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in src/node.cc, nel gestore ResetStdio, e riproduci il problema con il comando Bash riportato. Leggi il contesto da #24260 e #28535, inclusa la gestione di SIGTTOU e la chiamata a tcsetattr. È terminato quando un processo Node in background termina senza modificare il comportamento del terminale di Bash.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, linux, nodejs
- Ambito
- operating-systems
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100