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