denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.95k stars 5.4k forks source link

Deno task does not forward signal #18445

Open zifeo opened 1 year ago

zifeo commented 1 year ago
// test.ts
Deno.addSignalListener("SIGTERM", () => {
  console.log("term!");
  Deno.exit();
});

setTimeout(() => {}, 30000);
// deno.json
{
  "tasks": {
    "sleep": "deno run -A test.ts",
  }
}

Running deno run -A test.ts and kill -15 PID outputs:

term!

But deno task sleep and kill -15 PID (with the PID of the deno task runner, not the child deno process) outputs:

Task sleep deno run -A test.ts
fish: Job 1, 'deno task sleep' terminated by signal SIGTERM (Polite quit request)

The child process becomes a ghost, which is a pain to cleanup (e.g. an http server). I would expect deno task to behave like exec in bash or forward the signal to the child process.

All recent deno versions are affected.

yardenshoham commented 1 year ago

Duplicate of https://github.com/denoland/deno_task_shell/issues/33?

Hexagon commented 1 year ago

Following

chromakode commented 12 months ago

Just bumped into this as well. My Deno server process is unable to handle SIGTERM when run using deno task.

iacore commented 6 months ago

Can this be solved with execv? No because of pipeline. I looked at the code, and, easiest way is to have a global variable acting as pub/sub for signals. Passing it around like Go's sync.Context also works. I got lost in the async .await call hierarchy. Where in the code is the new process spawned?

Workaround to kill -15 PID not working: kill -- -PID

karimfromjordan commented 1 month ago

Just hit this issue too. I'm trying to spawn a server inside my test files to run API tests but the server never closes.

whiterqbbit commented 1 month ago

Same here