Open jtoppine opened 10 months ago
Small update:
Updated (edited) the repro above to also include tests for process.kill()
, just for completeness. It seems process.kill()
from the parent has the same effect as Deno.exit()
from inside the child.
I had brief discussion a couple of days earlier on discord with @marvinhagemeister , about an issue where it seems child processes are left inadvertedly alive after the parent process dies (acting like a detached process, effectively). I promised to create an issue about that. However, I'm starting to suspect that might not be a separate issue at all, but that this unref()
business described here is the root of both problems. I can only verify that after this issue is sorted out :)
There is a separate feature request to support explicit detached
processes, where it is actually desireable to let spawned childs to outlive the main process. One issue about that ( https://github.com/denoland/deno/issues/5501 ) has some discussion that may be relevant to this issue. Just mentioning here to link these loosely related things.
Version: Deno 1.39.0 / Linux
From
Deno.ChildProcess.unref()
docs: Ensure that the status of the child process does not block the Deno process from exiting.This seems to work in case of the parent process coming naturally to end (nothing to do). It also works when parent process encounters unhandled exception or rejection. But if parent process calls
Deno.exit()
, deno appears to wait for the child process to end before actually exiting, even ifunref()
was called on it.Encountered this while researching another subprocess related issue so this reproduction may have some extra stuff and is not exactly minimal. Anyway, you'll see how "exit-with-deno-exit" cases take about two seconds instead of returning immediately like the other test cases (child process self regulates if lifetime to max two seconds which is enough to verify behaviour).
Or is this intentional behaviour?
Note that the repro assumes it is saved as
subprocesstest.js
so that when it is run withdeno run -A subprocesstest.js
, it can run itself in a different "mode".It outputs this:
The expected output would be the same but without the
- test took too long, did parent process wait for child to exit?
lines.