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(ext/node): don't throw error for unsupported signal binding on windows #25699

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ext/node/polyfills/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ Process.prototype.on = function (
// Ignores SIGBREAK if the platform is not windows.
} else if (event === "SIGTERM" && Deno.build.os === "windows") {
// Ignores SIGTERM on windows.
} else if (
event !== "SIGBREAK" && event !== "SIGINT" && Deno.build.os === "windows"
) {
// Ignores all signals except SIGBREAK and SIGINT on windows.
// deno-lint-ignore no-console
console.warn(`Ignoring signal "${event}" on Windows`);
} else {
EventEmitter.prototype.on.call(this, event, listener);
Deno.addSignalListener(event as Deno.Signal, listener);
Expand All @@ -541,8 +547,10 @@ Process.prototype.off = function (
} else if (event.startsWith("SIG")) {
if (event === "SIGBREAK" && Deno.build.os !== "windows") {
// Ignores SIGBREAK if the platform is not windows.
} else if (event === "SIGTERM" && Deno.build.os === "windows") {
// Ignores SIGTERM on windows.
} else if (
event !== "SIGBREAK" && event !== "SIGINT" && Deno.build.os === "windows"
) {
// Ignores all signals except SIGBREAK and SIGINT on windows.
} else {
EventEmitter.prototype.off.call(this, event, listener);
Deno.removeSignalListener(event as Deno.Signal, listener);
Expand Down
28 changes: 28 additions & 0 deletions tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
assertThrows,
fail,
} from "@std/assert";
import { assertSpyCall, assertSpyCalls, spy } from "@std/testing/mock";
import { stripAnsiCode } from "@std/fmt/colors";
import * as path from "@std/path";
import { delay } from "@std/async/delay";
Expand Down Expand Up @@ -238,6 +239,33 @@ Deno.test({
},
});

Deno.test({
name: "process.on - ignored signals on windows",
ignore: Deno.build.os !== "windows",
fn() {
const ignoredSignals = ["SIGHUP", "SIGUSR1", "SIGUSR2"];

for (const signal of ignoredSignals) {
using consoleSpy = spy(console, "warn");
const handler = () => {};
process.on(signal, handler);
process.off(signal, handler);
assertSpyCall(consoleSpy, 0, {
args: [`Ignoring signal "${signal}" on Windows`],
});
}

{
using consoleSpy = spy(console, "warn");
const handler = () => {};
process.on("SIGTERM", handler);
process.off("SIGTERM", handler);
// No warning is made for SIGTERM
assertSpyCalls(consoleSpy, 0);
}
},
});

Deno.test(
{ permissions: { run: true, read: true } },
async function processKill() {
Expand Down