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.execFile / libuv spawn does not use self-binary #4459

Closed
cookiengineer opened this issue Dec 28, 2015 · 2 comments
Closed

child_process.execFile / libuv spawn does not use self-binary #4459

cookiengineer opened this issue Dec 28, 2015 · 2 comments
Labels
child_process Issues and PRs related to the child_process subsystem.

Comments

@cookiengineer
Copy link

The child_process.execFile API (which finally leads to a new ChildProcess() and spawn call via the internal wrapper) spawns a process that uses the native /usr/bin/env node binary and NOT the currently used one.

All versions (including 5.1.1) are affected. Problem is visible among all Debian based servers and systems. Probably all GNU/unix systems are affected as shebang leads to the specific problem.

STEPS TO REPRODUCE

  • Download new nodejs binary to ~/mytest/node-new
  • Download old nodejs binary to ~/mytest/node-old (every version applies and 5.1.1 is affected, too - so just use a different version number for the sake of comparison)

REDUCED TEST CASE

The ~/mytest/test.js:

console.log(process.version);

var cp = require('child_process');

cp.execFile(__dirname + '/child.js', [
  'foo',
  'bar'
], {
  cwd: __dirname
}, function(error, stdout, stderr) {
  console.log('execution finished', stdout);
});

The ~/mytest/child.js with the initial shebang that leads to the problem:

#!/usr/bin/env node

console.log(process.version);

Now execute the following command in the Terminal / bash:

cd ~/mytest;

sudo cp ./node-old /usr/bin/node; # Yes, we WANT this for reproduction of issue
sudo chmod 0777 /usr/bin/node; # Just to be sure it's executable

chmod +x ./node-new;
chmod +x ./test.js;
chmod +x ./child.js;
./node-new ./test.js;

TEST OUTPUT

./node-new app.js;
v5.1.1
execution finished v4.2.4

Is this the wanted behaviour?

It is nowhere documented and child_process as an API name suggests that forks of the self-binary are made and no new processes are spawned when JS files are executed.

@mscdex mscdex added the child_process Issues and PRs related to the child_process subsystem. label Dec 28, 2015
@bnoordhuis
Copy link
Member

Is this the wanted behaviour?

Yes, or at least, it's the expected behavior. The shebang is interpreted by the kernel; it executes env which in turn scans the PATH for node and executes that.

It is nowhere documented and child_process as an API name suggests that forks of the self-binary are made and no new processes are spawned when JS files are executed.

I'm not sure how you came to that conclusion. The reference documentation is pretty explicit on that point, IMO at least.

@cjihrig
Copy link
Contributor

cjihrig commented Dec 29, 2015

I'm going to close this as working as expected. However, if you think the documentation can be improved, I encourage you to try submitting a docs PR.

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.
Projects
None yet
Development

No branches or pull requests

4 participants