deno icon indicating copy to clipboard operation
deno copied to clipboard

Deno task does not forward signal

Open zifeo opened this issue 2 years ago • 6 comments

// 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.

zifeo avatar Mar 26 '23 16:03 zifeo

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

yardenshoham avatar May 01 '23 16:05 yardenshoham

Following

Hexagon avatar Jun 04 '23 18:06 Hexagon

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

chromakode avatar Nov 26 '23 02:11 chromakode

~~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

iacore avatar May 02 '24 16:05 iacore

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.

karimfromjordan avatar Oct 18 '24 19:10 karimfromjordan

Same here

whiterqbbit avatar Oct 20 '24 15:10 whiterqbbit

I think this is still an issue at least with task processes spawned using Deno.ChildProcess. I created a new issue for that. https://github.com/denoland/deno/issues/29590

KyleJune avatar Jun 04 '25 03:06 KyleJune

Bump. Still an issue. Some context: I am working on a turbo mono-repo, with a Deno2 api app. I launch with npm run dev, which runs turbo run dev, which for the deno api runs deno task dev. when I close my IDE or that window, the deno process stays orphaned. I do not have this issue with other nodeJS processes. They shut down when I close their parent terminal/window.

I now have to have a killDeno npm script (pkill -f 'deno' ) that runs everytime I launch. I wouldn't have to deal with stuff like this if I just trusted my gut and went with a Node api.

iyobo avatar Nov 25 '25 04:11 iyobo

@iyobo please open a new issue with a reproduction (the steps you mentioned don't seem to use deno task). The issue originally reported no longer reproduces and so this specific issue will remain closed.

dsherret avatar Nov 25 '25 04:11 dsherret

@dsherret It actually does use deno task. I had ellipsized it.

iyobo avatar Nov 25 '25 04:11 iyobo

@iyobo the issue originally reported no longer reproduces. Please open a new issue with a full reproduction so that we can fix whatever that problem is. It might not be related to deno task not forwarding signals, but whatever calls deno task.

dsherret avatar Nov 25 '25 04:11 dsherret