Open heypiotr opened 1 year ago
I suppose that isn't too surprising. Node closes libuv's uv_process_t
handles when the thread exits, meaning libuv won't reap the child processes when they exit. I don't think there's a nice, clean way to fix that.
Keeping the thread and handles around until the last child process exits works but turns into a resource leak when child processes don't exit.
Is it recommended to create a process in a worker thread in Node.js ?
I'd say users can reasonably expect that to work. This is just a design flaw-y edge case.
Version
v16.19.0, v18.14.0
Platform
Subsystem
child_process, worker_threads
What steps will reproduce the bug?
If you spawn a child process inside a worker thread, and then unref the child process, the process becomes a zombie when the worker thread exits.
This is a problem if you have a long-running main process that over the course of its lifetime spawns a lot of worker threads, because at some point you run out of PIDs.
index.mjs:
worker.mjs:
How often does it reproduce? Is there a required condition?
Repro'es every time with the provided snippets.
What is the expected behavior?
The child process gets removed from the processes table.
What do you see instead?
in another terminal window:
Additional information
No response