From 016fad4036ebca3e645aea23b185bc9184c256ce Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:12:16 +0200 Subject: [PATCH 1/3] Add isSigPipeError to handle epipe errors --- node/internal.ts | 9 +++++++++ node/task.ts | 6 ++++-- node/toolrunner.ts | 14 +++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/node/internal.ts b/node/internal.ts index d7c776aef..d31dd0bbd 100644 --- a/node/internal.ts +++ b/node/internal.ts @@ -1060,3 +1060,12 @@ function _exposeTaskLibSecret(keyFile: string, secret: string): string | undefin return new Buffer(storageFile).toString('base64') + ':' + new Buffer(encryptedContent).toString('base64'); } } + +export function isSigPipeError(e: unknown): e is Error { + if (!e || typeof e !== 'object') { + return false; + } + + const cast = e as Record; + return cast.code === 'EPIPE' && cast.syscall?.toUpperCase() === 'WRITE'; +} \ No newline at end of file diff --git a/node/task.ts b/node/task.ts index cfa22927a..d627e40d0 100644 --- a/node/task.ts +++ b/node/task.ts @@ -126,8 +126,10 @@ export function setSanitizedResult(result: TaskResult, message: string, done?: b // Catching all exceptions // process.on('uncaughtException', (err: Error) => { - setResult(TaskResult.Failed, loc('LIB_UnhandledEx', err.message)); - error(String(err.stack), im.IssueSource.TaskInternal); + if (!im.isSigPipeError(error)) { + setResult(TaskResult.Failed, loc('LIB_UnhandledEx', err.message)); + error(String(err.stack), im.IssueSource.TaskInternal); + } }); // diff --git a/node/toolrunner.ts b/node/toolrunner.ts index 48dcc2b73..29e93a134 100644 --- a/node/toolrunner.ts +++ b/node/toolrunner.ts @@ -671,7 +671,13 @@ export class ToolRunner extends events.EventEmitter { } }); } - + + cp.stdin?.on("error", (err: Error) => { + if (!im.isSigPipeError(error)) { + throw error; + } + }); + //pipe stdout of first tool to stdin of second tool cpFirst.stdout?.on('data', (data: Buffer) => { try { @@ -870,6 +876,12 @@ export class ToolRunner extends events.EventEmitter { }); } + cp.stdin?.on("error", (err: Error) => { + if (!im.isSigPipeError(error)) { + throw error; + } + }); + //pipe stdout of first tool to stdin of second tool cpFirst.stdout?.on('data', (data: Buffer) => { try { From 4f146c0400df4e7d3ca673a6d2c73ba536dcccc7 Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:54:49 +0200 Subject: [PATCH 2/3] Fix a problem when Error typecast to never type after isSigPipeError guard check --- node/internal.ts | 5 ++--- node/task.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/node/internal.ts b/node/internal.ts index d31dd0bbd..3b57b7261 100644 --- a/node/internal.ts +++ b/node/internal.ts @@ -1061,11 +1061,10 @@ function _exposeTaskLibSecret(keyFile: string, secret: string): string | undefin } } -export function isSigPipeError(e: unknown): e is Error { +export function isSigPipeError(e: NodeJS.ErrnoException): e is NodeJS.ErrnoException { if (!e || typeof e !== 'object') { return false; } - const cast = e as Record; - return cast.code === 'EPIPE' && cast.syscall?.toUpperCase() === 'WRITE'; + return e.code === 'EPIPE' && e.syscall?.toUpperCase() === 'WRITE'; } \ No newline at end of file diff --git a/node/task.ts b/node/task.ts index d627e40d0..2ecd05f73 100644 --- a/node/task.ts +++ b/node/task.ts @@ -126,7 +126,7 @@ export function setSanitizedResult(result: TaskResult, message: string, done?: b // Catching all exceptions // process.on('uncaughtException', (err: Error) => { - if (!im.isSigPipeError(error)) { + if (!im.isSigPipeError(err)) { setResult(TaskResult.Failed, loc('LIB_UnhandledEx', err.message)); error(String(err.stack), im.IssueSource.TaskInternal); } From 029f60dce98379b980e91532e7017eace436d20c Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:55:39 +0200 Subject: [PATCH 3/3] Fix variables names --- node/toolrunner.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node/toolrunner.ts b/node/toolrunner.ts index 29e93a134..65695b986 100644 --- a/node/toolrunner.ts +++ b/node/toolrunner.ts @@ -673,8 +673,8 @@ export class ToolRunner extends events.EventEmitter { } cp.stdin?.on("error", (err: Error) => { - if (!im.isSigPipeError(error)) { - throw error; + if (!im.isSigPipeError(err)) { + throw err; } }); @@ -877,8 +877,8 @@ export class ToolRunner extends events.EventEmitter { } cp.stdin?.on("error", (err: Error) => { - if (!im.isSigPipeError(error)) { - throw error; + if (!im.isSigPipeError(err)) { + throw err; } });