0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stdio-closed.js
Ben Noordhuis 506c7fd40b test: fix infinite spawn cycle in stdio test
Fix parallel/test-stdio-closed introduced in commit b5f25a9 ("src:
ensure that file descriptors 0-2 are valid") to not keep spawning
child processes ad infinitum.

The test spawns itself as a child process but a missing return statement
made the child process spawn itself again, and again, and again.

It went unnoticed for some time because the child process exits almost
immediately afterwards, i.e. it didn't fill up the process table.  The
observable effect was an iojs process that was quietly consuming CPU
cyles in the background with a PID that was constantly changing.

Refs: https://github.com/iojs/io.js/pull/938
PR-URL: https://github.com/iojs/io.js/pull/948
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2015-02-25 11:13:03 +01:00

26 lines
686 B
JavaScript

var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
if (process.platform === 'win32') {
console.log('Skipping test, platform not supported.');
return;
}
if (process.argv[2] === 'child') {
process.stdout.write('stdout', function() {
process.stderr.write('stderr', function() {
process.exit(42);
});
});
return;
}
// Run the script in a shell but close stdout and stderr.
var cmd = '"' + process.execPath + '" "' + __filename + '" child 1>&- 2>&-';
var proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
proc.on('exit', common.mustCall(function(exitCode) {
assert.equal(exitCode, 42);
}));