Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process.spawn detached not inheriting stdio on OSX starting with Node version 0.12 #4348

Closed
Jimbly opened this issue Dec 18, 2015 · 5 comments
Labels
child_process Issues and PRs related to the child_process subsystem. macos Issues and PRs related to the macOS platform / OSX.

Comments

@Jimbly
Copy link
Contributor

Jimbly commented Dec 18, 2015

The following statement on Linux (and on OSX with Node v0.10 and older) works as expected, but fails on OSX on Node v0.12 and up:

child_process.spawn('echo', ['test'], {stdio: 'inherit', detached: true });

On OSX, it now does not inherit the stdio handles, causing nothing to be outputted (and in the case of spawning anything more complicated than echo, can be seen to cause the child process to die almost immediately, presumably with EPIPE or something).

This was working fine in v0.10.x, does not work for me in v0.12.7, v4.2.3, or v5.3.0.

stdio: inhert + detached: true is useful for launching a process from a parent that might be killed/restarted, and letting the child continue (presumably with the parent launched redirecting output to a file for logging, etc).

I'm on OSX v10.9.5.

@mscdex mscdex added child_process Issues and PRs related to the child_process subsystem. macos Issues and PRs related to the macOS platform / OSX. labels Dec 18, 2015
@cjihrig
Copy link
Contributor

cjihrig commented Dec 21, 2015

Can you give a more concrete example that does not work?

Also, according to the docs, I'm not sure that stdio: inhert + detached: true would work exactly as you're expecting:

When using the detached option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a stdio configuration that is not connected to the parent. If the parent's stdio is inherited, the child will remain attached to the controlling terminal.

@Jimbly
Copy link
Contributor Author

Jimbly commented Dec 21, 2015

As described, the child should stay attached to the parent terminal. You
should see the result of the echo statement in the parent terminal, but
only on OSX you do not, instead the child dies.
On Dec 21, 2015 11:19 AM, "Colin Ihrig" notifications@github.com wrote:

Can you give a more concrete example that does not work?

Also, according to the docs, I'm not sure that stdio: inhert + detached:
true would work exactly as you're expecting:

When using the detached option to start a long-running process, the
process will not stay running in the background after the parent exits
unless it is provided with a stdio configuration that is not connected to
the parent. If the parent's stdio is inherited, the child will remain
attached to the controlling terminal.


Reply to this email directly or view it on GitHub
#4348 (comment).

@cjihrig
Copy link
Contributor

cjihrig commented Dec 21, 2015

The example you included in this issue works for me with latest master on OS X 10.11.1.

@Jimbly
Copy link
Contributor Author

Jimbly commented Dec 21, 2015

Interesting. I won't have access to a mac for a couple weeks due to the
holidays , but can try the latest build when I return. Might only be on
non-latest OSX versions or something, though old Node versions work fine.
Thanks for taking a look.

Definitely not a big issue, our code only hit this accidentally (usually
spawn detached plus redirected to file or attached and inherit anyway), but
seems wrong to behave differently on different platforms.
On Dec 21, 2015 12:11 PM, "Colin Ihrig" notifications@github.com wrote:

The example you included in this issue works for me with latest master on
OS X 10.11.1.


Reply to this email directly or view it on GitHub
#4348 (comment).

@indutny
Copy link
Member

indutny commented Dec 21, 2015

I believe this is a duplicate of #3596 . Closing this issue in a favor of that one, please let me know if you feel that this issue is different and should not be closed.

@indutny indutny closed this as completed Dec 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. macos Issues and PRs related to the macOS platform / OSX.
Projects
None yet
Development

No branches or pull requests

4 participants