KyleJuneK
Denoβ€’3y agoβ€’
8 replies
KyleJune

Killing subprocess not working

Anyone know what I'm doing wrong when trying to kill a process?

I have a process start another process like this:
runProcess = Deno.run({
  cmd: ["deno", "task", "run-dev"],
});

My child process uses deno task and the run-dev task starts an oak server.

Then if a file changes, I kill it with this.
runProcess.kill();
runProcess.close();

But I found that the server oak server keeps listening after I sent those. I tried awaiting runProcess.status() afterwards and it does resolve to { success: false, code: 143, signal: 15 } indicating it was killed, but the server is able to keep handling requests and if I try starting a new run-dev task, it will fail with an error saying the address is already in use. So it would appear the oak server isn't getting killed correctly. I even tried adding a 30 second delay between killing and restarting but it still fails to kill it.

The following output shows that I killed the process, but the oak server still was able to handle requests afterwards.

Restarting app
killing process
{ status: { success: false, code: 143, signal: 15 } }
{ status: 200, method: "GET", href: "http://localhost:9000/", responseTime: 4 }
{ status: 200, method: "GET", href: "http://localhost:9000/", responseTime: 2 }
{ status: 200, method: "GET", href: "http://localhost:9000/", responseTime: 3 }
Task run-dev export APP_ENV=development && deno run -A ./main.ts
error: Uncaught AddrInUse: Address already in use (os error 98)
      : Deno.listen(this.#options)) as Listener;
Was this page helpful?