fix #15369, prevent crash on unhandled EIO error in readStdin cleanup (#15410)

Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
This commit is contained in:
ElecTwix
2025-12-22 23:50:43 +03:00
committed by GitHub
parent 9c48cd849b
commit 0a216b28f3
3 changed files with 105 additions and 0 deletions
+9
View File
@@ -62,6 +62,13 @@ export async function readStdin(): Promise<string> {
process.stdin.removeListener('readable', onReadable);
process.stdin.removeListener('end', onEnd);
process.stdin.removeListener('error', onError);
// Add a no-op error listener if no other error listeners are present to prevent
// unhandled 'error' events (like EIO) from crashing the process after we stop reading.
// This is especially important for background execution where TTY might cause EIO.
if (process.stdin.listenerCount('error') === 0) {
process.stdin.on('error', noopErrorHandler);
}
};
process.stdin.on('readable', onReadable);
@@ -69,3 +76,5 @@ export async function readStdin(): Promise<string> {
process.stdin.on('error', onError);
});
}
function noopErrorHandler() {}