diff --git a/ext/process/40_process.js b/ext/process/40_process.js index a4afe336bd..dc11cae020 100644 --- a/ext/process/40_process.js +++ b/ext/process/40_process.js @@ -299,9 +299,14 @@ class ChildProcess { this.#stderr = readableStreamForRidUnrefable(stderrRid); } - const onAbort = () => this.kill("SIGTERM"); + const onAbort = () => { + try { + this.kill("SIGTERM"); + } catch { + // Ignore the error for https://github.com/denoland/deno/issues/27112 + } + }; signal?.[abortSignal.add](onAbort); - const waitPromise = op_spawn_wait(this.#rid); this.#waitPromise = waitPromise; this.#status = PromisePrototypeThen(waitPromise, (res) => { diff --git a/tests/unit/command_test.ts b/tests/unit/command_test.ts index fa941df0dc..ea05b236d7 100644 --- a/tests/unit/command_test.ts +++ b/tests/unit/command_test.ts @@ -1093,3 +1093,21 @@ Deno.test( assertEquals(child.success, true); }, ); + +Deno.test( + { ignore: Deno.build.os === "windows" }, + async function abortChildProcessRightWhenItExitsShouldNotThrow() { + const controller = new AbortController(); + const cb = () => controller.abort(); + Deno.addSignalListener("SIGCHLD", cb); + const output = await new Deno.Command("true", { signal: controller.signal }) + .output(); + assertEquals(output.success, true); + assertEquals(output.code, 0); + assertEquals(output.signal, null); + assertEquals(output.stdout, new Uint8Array()); + assertEquals(output.stderr, new Uint8Array()); + + Deno.removeSignalListener("SIGCHLD", cb); + }, +);