Windows ConPTY: unhandled 'error' event on conout/conin sockets + re-throw in error handler kills the embedding host
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
- Ambito
- backend, operating-systems
Direzione di ricerca
Inizia in lib/windowsPtyAgent.js, intorno alla costruzione di _outSocket e _inSocket, quindi segui il percorso _failPtyConnection esistente. Leggi la gestione degli errori dei socket in lib/windowsTerminal.js e verifica come ready_datapipe e agent.onError portano alla pulizia. Il lavoro è completato quando le pipe ConPTY danneggiate non producono più un'eccezione non gestita né terminano l'host che le integra; la verifica riportata ha usato node --check.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Windows ConPTY (named pipe) sockets created in WindowsPtyAgent have no 'error' listener at construction time, and WindowsTerminal's error handler re-throws non-EIO errors from inside the 'error' event. Both paths turn a broken ConPTY pipe into an uncaught exception that kills the whole host process (observed twice, e.g. exit code 1 with the classic Unhandled 'error' event dump and once with 0xC0000005).
Version: 1.2.0-beta.15 on Windows (Node v24.14.0), consumed via dsh-subprocess-local.spawnTerminal.
Repro / trigger
Any long-running persistent PTY whose ConPTY pipe breaks while the host is alive:
- child process tree killed externally (e.g.
taskkill /T, cleanup tools, watchdog scripts) - machine sleep/wake invalidating the pipe
- connection timeout / worker failure before
ready_datapipe
Once the pipe breaks, the next socket read/write fails with Error: read UNKNOWN (errno: -4094, code: 'UNKNOWN') and the whole embedding process dies.
Evidence
Host-process stderr captured at crash:
node:events:486
throw er; // Unhandled 'error' event
^
Error: read UNKNOWN
at Pipe.onStreamRead (node:internal/stream_base_commons:216:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'read'
}
Node.js v24.14.0
Root cause (code)
lib/windowsPtyAgent.js (constructor, ~lines 56-93):
this._outSocket = new net_1.Socket();
...
this._outSocket.on('connect', function () {
_this._outSocket.emit('ready_datapipe');
});
var inSocketFD = fs.openSync(term.conin, 'w');
this._inSocket = new net_1.Socket({ fd: inSocketFD, readable: false, writable: true });
_outSocket: the'error'listener is only attached later inwindowsTerminal.jsinside theready_datapipecallback — before that fires, an error on this socket is unhandled → process crash._inSocket: never gets an'error'listener at all → any write/read error =Unhandled 'error' event→ process crash.
lib/windowsTerminal.js (~lines 89-105):
_this._socket.on('error', function (err) {
_this._close();
if (err.code) {
if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) return;
}
// Throw anything else.
if (_this.listeners('error').length < 2) {
throw err; // throw from inside an 'error' handler = uncaught exception
}
});
Suggested fix
- Attach
'error'handlers on both sockets immediately after creation inWindowsPtyAgent, funneling into the existing_failPtyConnectionpath (which firesonError→ terminalexit→ graceful cleanup). - Remove/replace the
throw errinWindowsTerminal— errors already flow viaagent.onError→exit; re-throwing from an'error'listener is a process-killer for embedding consumers.
I applied exactly these two changes locally (verified with node --check) and the host process no longer dies on the broken-pipe path.
- Lingua principale
- TypeScript
- Stelle
- 2k
- Fork
- 337
- Merge medio
- 13h 17m
- PR unite (30g)
- 5
Preparare l'ambiente
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.
Altre issue di microsoft/node-pty
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/node-pty#951 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Windows: conin socket has no 'error' listener, so a failed pty write is an uncaught exceptionAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/node-pty
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
external-issue to-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
diegosouzapw/OmniRoute#15401 ·
I maintainer di solito rispondono entro 2 giorni
-
Sign the pledgeAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
input-output-hk/devx-updates#163 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
code-yeongyu/oh-my-openagent#9454 ·
I maintainer di solito rispondono entro 1 giorno