FAQ
See https://gist.github.com/3751746 for details.

Basically, in Node 0.6, if you start a child_process with
child_process.spawn, the pipe2 system call was used to create the
pipes between parent and child.

This was changed (I believe) in this commit by indutny:
https://github.com/joyent/libuv/commit/c0081f0e6675131721dbb5138fd398792a8c2163

Now the socketpair call is used to create those fds.

I'm not sure why that choice was made, but it has at least one bad
effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0"
on the child, at least on Linux.

The gist shows a Node program that basically just spawns "cat
/proc/self/fd/0", closes the pipe to the cat, and shows what the cat
outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In
0.8.8 cat fails to open the /proc/self/fd/0.

The C program in the gist shows that the difference really is just
socketpair vs pipe2. If you run the version with pipe2 the open call
succeeds. Comment out pipe2 and uncomment socketpair, and the open
call fails.

Was this behavior change intentional?
What benefits are created by switching from pipe2 to socketpair?

--dave

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Ben Noordhuis at Sep 19, 2012 at 10:26 pm

    On Wed, Sep 19, 2012 at 9:54 PM, David Glasser wrote:
    See https://gist.github.com/3751746 for details.

    Basically, in Node 0.6, if you start a child_process with
    child_process.spawn, the pipe2 system call was used to create the
    pipes between parent and child.

    This was changed (I believe) in this commit by indutny:
    https://github.com/joyent/libuv/commit/c0081f0e6675131721dbb5138fd398792a8c2163

    Now the socketpair call is used to create those fds.

    I'm not sure why that choice was made, but it has at least one bad
    effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0"
    on the child, at least on Linux.

    The gist shows a Node program that basically just spawns "cat
    /proc/self/fd/0", closes the pipe to the cat, and shows what the cat
    outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In
    0.8.8 cat fails to open the /proc/self/fd/0.

    The C program in the gist shows that the difference really is just
    socketpair vs pipe2. If you run the version with pipe2 the open call
    succeeds. Comment out pipe2 and uncomment socketpair, and the open
    call fails.

    Was this behavior change intentional? Yes.
    What benefits are created by switching from pipe2 to socketpair?
    The ability to send file descriptors to the child process (which was
    something you could do in v0.4 but not v0.6).

    It's been brought up on the issue tracker a few times. A
    straightforward workaround is to insert a pipe. E.g.:

    spawn('foo')

    Becomes:

    spawn('/bin/sh', ['-c', 'cat | foo'])

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • David Glasser at Sep 19, 2012 at 11:17 pm
    Ah, yes, that'll do it. And yes, that's the workaround we're using.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Dhruvbird at Sep 20, 2012 at 2:07 pm
    Hello,

    So, I'm still trying to understand the implications of this change. Suppose
    I spawn "cat" and write to the stdin of the spawned process, then will the
    "cat" process not be able to read it?

    var cat = spawn('cat');
    cat.stdin.write('Foo Bar');
    cat.stdout.on('data', function(d) { console.log("Child Says:", String(d);
    });

    Will this do what I expect it to?

    On Wednesday, September 19, 2012 6:20:23 PM UTC-4, Ben Noordhuis wrote:
    On Wed, Sep 19, 2012 at 9:54 PM, David Glasser wrote:
    See https://gist.github.com/3751746 for details.

    Basically, in Node 0.6, if you start a child_process with
    child_process.spawn, the pipe2 system call was used to create the
    pipes between parent and child.

    This was changed (I believe) in this commit by indutny:
    https://github.com/joyent/libuv/commit/c0081f0e6675131721dbb5138fd398792a8c2163
    Now the socketpair call is used to create those fds.

    I'm not sure why that choice was made, but it has at least one bad
    effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0"
    on the child, at least on Linux.

    The gist shows a Node program that basically just spawns "cat
    /proc/self/fd/0", closes the pipe to the cat, and shows what the cat
    outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In
    0.8.8 cat fails to open the /proc/self/fd/0.

    The C program in the gist shows that the difference really is just
    socketpair vs pipe2. If you run the version with pipe2 the open call
    succeeds. Comment out pipe2 and uncomment socketpair, and the open
    call fails.

    Was this behavior change intentional? Yes.
    What benefits are created by switching from pipe2 to socketpair?
    The ability to send file descriptors to the child process (which was
    something you could do in v0.4 but not v0.6).

    It's been brought up on the issue tracker a few times. A
    straightforward workaround is to insert a pipe. E.g.:

    spawn('foo')

    Becomes:

    spawn('/bin/sh', ['-c', 'cat | foo'])
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Noordhuis at Sep 20, 2012 at 3:18 pm

    On Thu, Sep 20, 2012 at 4:07 PM, dhruvbird wrote:
    Hello,

    So, I'm still trying to understand the implications of this change. Suppose
    I spawn "cat" and write to the stdin of the spawned process, then will the
    "cat" process not be able to read it?

    var cat = spawn('cat');
    cat.stdin.write('Foo Bar');
    cat.stdout.on('data', function(d) { console.log("Child Says:", String(d);
    });

    Will this do what I expect it to?
    Yes. It's only when the child process explicitly opens /dev/stdin (or
    /dev/stdout) that it doesn't work.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Shawn Parrish at Sep 25, 2012 at 10:44 pm
    Ben,

    I noticed this line in the announcement for 0.8.10

    * unix: put child process stdio fds in blocking mode (Ben Noordhuis)

    Does that by any chance address this issue? I continue to struggle with it.

    Thanks,
    Shawn

    On Thu, Sep 20, 2012 at 9:18 AM, Ben Noordhuis wrote:
    On Thu, Sep 20, 2012 at 4:07 PM, dhruvbird wrote:
    Hello,

    So, I'm still trying to understand the implications of this change. Suppose
    I spawn "cat" and write to the stdin of the spawned process, then will the
    "cat" process not be able to read it?

    var cat = spawn('cat');
    cat.stdin.write('Foo Bar');
    cat.stdout.on('data', function(d) { console.log("Child Says:", String(d);
    });

    Will this do what I expect it to?
    Yes. It's only when the child process explicitly opens /dev/stdin (or
    /dev/stdout) that it doesn't work.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Noordhuis at Sep 25, 2012 at 11:24 pm

    On Wed, Sep 26, 2012 at 12:43 AM, Shawn Parrish wrote:
    Ben,

    I noticed this line in the announcement for 0.8.10

    * unix: put child process stdio fds in blocking mode (Ben Noordhuis)

    Does that by any chance address this issue? I continue to struggle with it.
    No, that fixes another issue: child processes going wild because they
    don't expect stdio to be non-blocking. Only happens in some cases.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedSep 19, '12 at 10:02p
activeSep 25, '12 at 11:24p
posts7
users4
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase