Windows ConPTY: unhandled 'error' event on conout/conin sockets + re-throw in error handler kills the embedding host
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
- Área
- backend, operating-systems
Línea de trabajo
Empieza en lib/windowsPtyAgent.js, alrededor de la construcción de _outSocket y _inSocket, y sigue después la ruta existente _failPtyConnection. Lee el manejo de errores de sockets en lib/windowsTerminal.js y comprueba cómo ready_datapipe y agent.onError conducen a la limpieza. Se considera terminado cuando las tuberías ConPTY rotas ya no producen una excepción no capturada ni terminan el host que las integra; la verificación indicada utilizó node --check.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 2k
- Forks
- 337
- Merge medio
- 21 h 58 min
- PR fusionados (30 d)
- 3
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/node-pty
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Windows: conin socket has no 'error' listener, so a failed pty write is an uncaught exception Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Todos los issues de microsoft/node-pty
Issues similares
-
bot:ai-assisted component:compact-js status:untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
midnightntwrk/midnight-sdk#403 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
joinmarket-webui/jam#1496 · 1 comentario ·
-
Tech
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
opencrvs/opencrvs-core#13865 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
linagora/twake-calendar-frontend#1377 · 1 comentario ·
-
Claiming namespace Londopy Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
EclipseFdn/open-vsx.org#13385 · 1 comentario ·