Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle signal 0 in process.kill #23473

Merged
merged 13 commits into from
May 19, 2024
4 changes: 4 additions & 0 deletions ext/node/polyfills/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ memoryUsage.rss = function (): number {

// Returns a negative error code than can be recognized by errnoException
function _kill(pid: number, sig: number): number {
// signal 0 does not exist in constants.os.signals, thats why it have to be handled explicitly
if (sig === 0) {
return op_node_process_kill(pid, 0);
}
const maybeSignal = Object.entries(constants.os.signals).find((
[_, numericCode],
) => numericCode === sig);
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ Deno.test(
args: ["eval", "setTimeout(() => {}, 10000)"],
}).spawn();

// kill with signal 0 should keep the process alive in linux (true means no error happened)
// windows ignore signals
if (Deno.build.os !== "windows") {
assertEquals(process.kill(p.pid, 0), true);
}
process.kill(p.pid);
await p.status;
},
Expand Down