child_process: change the defaults maxBuffer size

PR-URL: https://github.com/nodejs/node/pull/27179
Refs: https://github.com/nodejs/node/pull/23027
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
kohta ito 2019-04-11 03:26:58 +09:00 committed by Sam Roberts
parent 69140bc7f8
commit 652877e3a9
8 changed files with 42 additions and 30 deletions

View File

@ -151,7 +151,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][]. truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`. **Default:** `1024 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'` * `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)). * `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)). * `gid` {number} Sets the group identity of the process (see setgid(2)).
@ -250,7 +250,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][]. truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`. **Default:** `1024 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'` * `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)). * `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)). * `gid` {number} Sets the group identity of the process (see setgid(2)).
@ -721,7 +721,7 @@ changes:
process will be killed. **Default:** `'SIGTERM'`. process will be killed. **Default:** `'SIGTERM'`.
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated. See caveat at stderr. If exceeded, the child process is terminated. See caveat at
[`maxBuffer` and Unicode][]. **Default:** `200 * 1024`. [`maxBuffer` and Unicode][]. **Default:** `1024 * 1024`.
* `encoding` {string} The encoding used for all stdio inputs and outputs. * `encoding` {string} The encoding used for all stdio inputs and outputs.
**Default:** `'buffer'`. **Default:** `'buffer'`.
* `windowsHide` {boolean} Hide the subprocess console window that would * `windowsHide` {boolean} Hide the subprocess console window that would
@ -788,7 +788,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][]. truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`. **Default:** `1024 * 1024`.
* `encoding` {string} The encoding used for all stdio inputs and outputs. * `encoding` {string} The encoding used for all stdio inputs and outputs.
**Default:** `'buffer'`. **Default:** `'buffer'`.
* `windowsHide` {boolean} Hide the subprocess console window that would * `windowsHide` {boolean} Hide the subprocess console window that would
@ -852,7 +852,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][]. truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`. **Default:** `1024 * 1024`.
* `encoding` {string} The encoding used for all stdio inputs and outputs. * `encoding` {string} The encoding used for all stdio inputs and outputs.
**Default:** `'buffer'`. **Default:** `'buffer'`.
* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses * `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses

View File

@ -49,7 +49,7 @@ const {
ChildProcess ChildProcess
} = child_process; } = child_process;
const MAX_BUFFER = 200 * 1024; const MAX_BUFFER = 1024 * 1024;
exports.ChildProcess = ChildProcess; exports.ChildProcess = ChildProcess;

View File

@ -12,7 +12,8 @@ function runChecks(err, stdio, streamName, expected) {
// default value // default value
{ {
const cmd = `"${process.execPath}" -e "console.log('a'.repeat(200 * 1024))"`; const cmd =
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`;
cp.exec(cmd, common.mustCall((err) => { cp.exec(cmd, common.mustCall((err) => {
assert(err instanceof RangeError); assert(err instanceof RangeError);
@ -24,11 +25,11 @@ function runChecks(err, stdio, streamName, expected) {
// default value // default value
{ {
const cmd = const cmd =
`${process.execPath} -e "console.log('a'.repeat(200 * 1024 - 1))"`; `${process.execPath} -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
cp.exec(cmd, common.mustCall((err, stdout, stderr) => { cp.exec(cmd, common.mustCall((err, stdout, stderr) => {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1)); assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, ''); assert.strictEqual(stderr, '');
})); }));
} }
@ -58,12 +59,18 @@ function runChecks(err, stdio, streamName, expected) {
// default value // default value
{ {
const cmd = `"${process.execPath}" -e "console.log('a'.repeat(200 * 1024))"`; const cmd =
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`;
cp.exec( cp.exec(
cmd, cmd,
common.mustCall((err, stdout, stderr) => { common.mustCall((err, stdout, stderr) => {
runChecks(err, { stdout, stderr }, 'stdout', 'a'.repeat(200 * 1024)); runChecks(
err,
{ stdout, stderr },
'stdout',
'a'.repeat(1024 * 1024)
);
}) })
); );
} }
@ -71,11 +78,11 @@ function runChecks(err, stdio, streamName, expected) {
// default value // default value
{ {
const cmd = const cmd =
`"${process.execPath}" -e "console.log('a'.repeat(200 * 1024 - 1))"`; `"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
cp.exec(cmd, common.mustCall((err, stdout, stderr) => { cp.exec(cmd, common.mustCall((err, stdout, stderr) => {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1)); assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, ''); assert.strictEqual(stderr, '');
})); }));
} }

View File

@ -15,7 +15,7 @@ function checkFactory(streamName) {
{ {
execFile( execFile(
process.execPath, process.execPath,
['-e', 'console.log("a".repeat(200 * 1024))'], ['-e', 'console.log("a".repeat(1024 * 1024))'],
checkFactory('stdout') checkFactory('stdout')
); );
} }
@ -24,10 +24,10 @@ function checkFactory(streamName) {
{ {
execFile( execFile(
process.execPath, process.execPath,
['-e', 'console.log("a".repeat(200 * 1024 - 1))'], ['-e', 'console.log("a".repeat(1024 * 1024 - 1))'],
common.mustCall((err, stdout, stderr) => { common.mustCall((err, stdout, stderr) => {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1)); assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, ''); assert.strictEqual(stderr, '');
}) })
); );

View File

@ -35,12 +35,12 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf); assert.deepStrictEqual(ret, msgOutBuf);
} }
// Default maxBuffer size is 200 * 1024. // Default maxBuffer size is 1024 * 1024.
{ {
assert.throws(() => { assert.throws(() => {
execFileSync( execFileSync(
process.execPath, process.execPath,
['-e', "console.log('a'.repeat(200 * 1024))"] ['-e', "console.log('a'.repeat(1024 * 1024))"]
); );
}, (e) => { }, (e) => {
assert.ok(e, 'maxBuffer should error'); assert.ok(e, 'maxBuffer should error');

View File

@ -34,13 +34,13 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf); assert.deepStrictEqual(ret, msgOutBuf);
} }
// maxBuffer size is 200 * 1024 at default. // maxBuffer size is 1024 * 1024 at default.
{ {
assert.throws( assert.throws(
() => { () => {
execFileSync( execFileSync(
process.execPath, process.execPath,
['-e', "console.log('a'.repeat(200 * 1024))"], ['-e', "console.log('a'.repeat(1024 * 1024))"],
{ encoding: 'utf-8' } { encoding: 'utf-8' }
); );
}, (e) => { }, (e) => {

View File

@ -38,10 +38,12 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf); assert.deepStrictEqual(ret, msgOutBuf);
} }
// Default maxBuffer size is 200 * 1024. // Default maxBuffer size is 1024 * 1024.
{ {
assert.throws(() => { assert.throws(() => {
execSync(`"${process.execPath}" -e "console.log('a'.repeat(200 * 1024))"`); execSync(
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`
);
}, (e) => { }, (e) => {
assert.ok(e, 'maxBuffer should error'); assert.ok(e, 'maxBuffer should error');
assert.strictEqual(e.errno, 'ENOBUFS'); assert.strictEqual(e.errno, 'ENOBUFS');
@ -49,11 +51,14 @@ const args = [
}); });
} }
// Default maxBuffer size is 200 * 1024. // Default maxBuffer size is 1024 * 1024.
{ {
const ret = execSync( const ret = execSync(
`"${process.execPath}" -e "console.log('a'.repeat(200 * 1024 - 1))"` `"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024 - 1))"`
); );
assert.deepStrictEqual(ret.toString().trim(), 'a'.repeat(200 * 1024 - 1)); assert.deepStrictEqual(
ret.toString().trim(),
'a'.repeat(1024 * 1024 - 1)
);
} }

View File

@ -33,23 +33,23 @@ const args = [
assert.deepStrictEqual(ret.stdout, msgOutBuf); assert.deepStrictEqual(ret.stdout, msgOutBuf);
} }
// Default maxBuffer size is 200 * 1024. // Default maxBuffer size is 1024 * 1024.
{ {
const args = ['-e', "console.log('a'.repeat(200 * 1024))"]; const args = ['-e', "console.log('a'.repeat(1024 * 1024))"];
const ret = spawnSync(process.execPath, args); const ret = spawnSync(process.execPath, args);
assert.ok(ret.error, 'maxBuffer should error'); assert.ok(ret.error, 'maxBuffer should error');
assert.strictEqual(ret.error.errno, 'ENOBUFS'); assert.strictEqual(ret.error.errno, 'ENOBUFS');
} }
// Default maxBuffer size is 200 * 1024. // Default maxBuffer size is 1024 * 1024.
{ {
const args = ['-e', "console.log('a'.repeat(200 * 1024 - 1))"]; const args = ['-e', "console.log('a'.repeat(1024 * 1024 - 1))"];
const ret = spawnSync(process.execPath, args); const ret = spawnSync(process.execPath, args);
assert.ifError(ret.error); assert.ifError(ret.error);
assert.deepStrictEqual( assert.deepStrictEqual(
ret.stdout.toString().trim(), ret.stdout.toString().trim(),
'a'.repeat(200 * 1024 - 1) 'a'.repeat(1024 * 1024 - 1)
); );
} }