fix(runtime): Restore default signal handler after user handlers are unregistered (#22757)

<!--
Before submitting a PR, please read
https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->

Fixes #22724. Fixes #7164.

This does add a dependency on `signal-hook`, but it's just a higher
level API on top of `signal-hook-registry` (which we and `tokio` already
depend on) and doesn't add any transitive deps.
This commit is contained in:
Nathan Whitaker 2024-03-11 10:22:28 -07:00 committed by GitHub
parent 670e9a9be7
commit 28b362adfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 102 additions and 7 deletions

View file

@ -237,7 +237,7 @@ Deno.test({
Deno.test({
name: "process.off signal",
ignore: true, // This test fails to terminate
ignore: Deno.build.os == "windows",
async fn() {
const testTimeout = setTimeout(() => fail("Test timed out"), 10_000);
try {
@ -246,13 +246,13 @@ Deno.test({
"eval",
`
import process from "node:process";
console.log("ready");
setInterval(() => {}, 1000);
const listener = () => {
process.off("SIGINT", listener);
console.log("foo");
process.off("SIGINT", listener)
};
process.on("SIGINT", listener);
console.log("ready");
`,
],
stdout: "piped",
@ -275,6 +275,7 @@ Deno.test({
while (!output.includes("foo\n")) {
await delay(10);
}
process.kill("SIGINT");
await process.status;
} finally {
clearTimeout(testTimeout);