Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Node 0.8 breaks use of /dev/stdin in child processes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Glasser  
View profile  
 More options Sep 19 2012, 3:54 pm
From: David Glasser <glas...@meteor.com>
Date: Wed, 19 Sep 2012 12:54:09 -0700
Local: Wed, Sep 19 2012 3:54 pm
Subject: Node 0.8 breaks use of /dev/stdin in child processes
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/c0081f0e6675131721dbb5138fd398...

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Noordhuis  
View profile  
 More options Sep 19 2012, 6:20 pm
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Thu, 20 Sep 2012 00:20:13 +0200
Local: Wed, Sep 19 2012 6:20 pm
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes

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'])


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Glasser  
View profile  
 More options Sep 19 2012, 7:09 pm
From: David Glasser <glas...@meteor.com>
Date: Wed, 19 Sep 2012 16:09:44 -0700 (PDT)
Local: Wed, Sep 19 2012 7:09 pm
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes

Ah, yes, that'll do it. And yes, that's the workaround we're using.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dhruvbird  
View profile  
 More options Sep 20 2012, 10:07 am
From: dhruvbird <dhruvb...@gmail.com>
Date: Thu, 20 Sep 2012 07:07:02 -0700 (PDT)
Local: Thurs, Sep 20 2012 10:07 am
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes

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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Noordhuis  
View profile  
 More options Sep 20 2012, 11:18 am
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Thu, 20 Sep 2012 17:18:42 +0200
Local: Thurs, Sep 20 2012 11:18 am
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes

On Thu, Sep 20, 2012 at 4:07 PM, dhruvbird <dhruvb...@gmail.com> 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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shawn Parrish  
View profile  
 More options Sep 25 2012, 6:44 pm
From: Shawn Parrish <sparr...@nodeping.com>
Date: Tue, 25 Sep 2012 16:43:49 -0600
Local: Tues, Sep 25 2012 6:43 pm
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Noordhuis  
View profile  
 More options Sep 25 2012, 7:24 pm
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Wed, 26 Sep 2012 01:24:45 +0200
Local: Tues, Sep 25 2012 7:24 pm
Subject: Re: [nodejs] Node 0.8 breaks use of /dev/stdin in child processes

On Wed, Sep 26, 2012 at 12:43 AM, Shawn Parrish <sparr...@nodeping.com> 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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »