This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
child_process: Expose 'detached' option to allow spawning detached child processes #2832
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This functionality now exists in libuv master -
uv_spawn()
is now able to spawn detached (i.e. daemonized) child processes on both unix and Windows.This patch exposes that option to Node.JS userland as a
detached
option tochild_process.spawn
.Despite the fact that the
stdio
streams created in js are closed inlibuv
, the child closing its streams and exiting isn't enough to tellchild_process.js
that the child has exited.this._internal.onexit
is called successfully, but themaybeExit
function is explicitly waiting forclose
events from the number of streams that were opened in js. Despite the fact that the underlying streams have been closed, theclose
events on thestdio
streams in node don't fire of their own accord.This keeps the parent process alive indefinitely, as the criteria specified for emitting the
exit
event will never occur.Since a detached process is semantically somewhat different than a normal child process that exits, a separate
detached
event seemed like a good way to solve this. If the process being spawned is detached, the parent now emits adetached
event without waiting for the otherclose
events.It might be better to somehow close or destroy the
stdout
andstderr
streams, but the event loop doesn't seem to care, and node exits just fine.