Skip to content

Commit fc2ceb1

Browse files
author
Andrea Cosentino
committed
fix: stdout/stderr uncaughtException
1 parent 05d4e74 commit fc2ceb1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/plugin/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ export function universalApiPlugin(opts?: UniversalApiOptions): Plugin {
3131

3232
logger.info(`plugin ${options.disable ? "disabled" : "started"}`);
3333
logger.debug("Vite configResolved: FINISH");
34+
/* v8 ignore start */
35+
/**
36+
* INFO
37+
* plugin print on process.stoud/sterr with console. If the process running in background,
38+
* when client disconnect session, stdout/stderr receive EIO/EPIPE error.
39+
* So register an hanlder to avoid process's death for uncaughtException
40+
*/
41+
const suppressIoError = (err: NodeJS.ErrnoException) => {
42+
if (err.code !== 'EIO' && err.code !== 'EPIPE') {
43+
throw err;
44+
}
45+
};
46+
if (process.stdout.listenerCount('error') === 0) {
47+
process.stdout.on('error', suppressIoError);
48+
}
49+
if (process.stderr.listenerCount('error') === 0) {
50+
process.stderr.on('error', suppressIoError);
51+
}
52+
/* v8 ignore stop */
3453
},
3554
configureServer(server) {
3655
if (options.disable) {

0 commit comments

Comments
 (0)