Moomoo
Moomoo•3w ago

Child process doesn't exit on .kill()

I have a Fastify Node app that I'm running from Deno as a child process. I can spawn the child process just fine, and see that it's all running as expected. When I call .kill() and await the .status, I can see it exits with a status code of 1. If the script then waits (even a full minute) and spawns a new child process of the same Node app, I get an EADDRINUSE error. If, instead, I exit the Deno app and start it again (in well under a minute), the first child process spawns fine and the desired port is available. It looks like, despite returning an exit code, the child process isn't actually terminated while the Deno app keeps running. I can even see the Node process still in my task manager after it's supposedly been terminated. Once I exit the Deno process, the Node processes disappear immediately. The exit code of 1 probably means that something's wrong, but nothing's coming in over stdout or stderr. FWIW, I get the same when I try to run a Vite dev server instead of a Fastify app, with the same result. Anyone know what I'm doing wrong? Edit: I'm using Deno 1.46.3 on Windows, in case that's relevant.
4 Replies
jeff.hykin
jeff.hykin•3w ago
Probably need to do .kill("SIGKILL") since I believe by default it only sends SIGSTOP But thats for Linux/Mac so idk if there's a windows specific issue going on here
Moomoo
Moomoo•3w ago
Hey, thanks for your response 🙂 .kill() sends SIGTERM by default. I tried SIGKILL to no avail, and when I try SIGINT I get a TypeError: Invalid signal: SIGINT. But I did just spot in lib.deno.ns.d.ts that
On Windows only "SIGINT" (CTRL+C) and "SIGBREAK" (CTRL+Break) are supported.
So I'll give SIGBREAK a shot. Hm, on SIGBREAK I also get the Invalid signal error. Ok, so it looks like SIGINT and SIGBREAK are not implemented on Windows, and they're not going to be. I have no idea how we're suppoesd to kill child processes on Windows if the only two signals that are supported aren't actually supported. Well, I got something working by calling wmic process where ParentProcessId='${pid}' get ProcessId to recursively get all the child process PIDs of the process I want to kill, and killing them all individually. I'm not sure if that's the recommended way of doing it, but it seems to work.
jeff.hykin
jeff.hykin•3w ago
Thats rough, but hey if it works it works
Moomoo
Moomoo•3w ago
Yeah I'm just glad I'm just making a little development tool for myself and not something that needs to run in production somewhere. It looks like Deno was actually killing the process I spawned, but not any child processes that spawned in turn, so I need to do that manually. Anyway, thank you for he help 🙂