mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
fix(ext/process): suppress child process kill errors in onAbort handler (#29193)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
This commit is contained in:
parent
8e9db221ed
commit
19c5cca65e
2 changed files with 25 additions and 2 deletions
|
@ -299,9 +299,14 @@ class ChildProcess {
|
||||||
this.#stderr = readableStreamForRidUnrefable(stderrRid);
|
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);
|
signal?.[abortSignal.add](onAbort);
|
||||||
|
|
||||||
const waitPromise = op_spawn_wait(this.#rid);
|
const waitPromise = op_spawn_wait(this.#rid);
|
||||||
this.#waitPromise = waitPromise;
|
this.#waitPromise = waitPromise;
|
||||||
this.#status = PromisePrototypeThen(waitPromise, (res) => {
|
this.#status = PromisePrototypeThen(waitPromise, (res) => {
|
||||||
|
|
|
@ -1093,3 +1093,21 @@ Deno.test(
|
||||||
assertEquals(child.success, true);
|
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);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue