Skip to content

Commit

Permalink
child_process: change the defaults maxBuffer size
Browse files Browse the repository at this point in the history
PR-URL: #27179
Refs: #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>
  • Loading branch information
koh110 authored and sam-github committed Apr 17, 2019
1 parent 69140bc commit 652877e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 30 deletions.
10 changes: 5 additions & 5 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`.
**Default:** `1024 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)).
Expand Down Expand Up @@ -250,7 +250,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`.
**Default:** `1024 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)).
Expand Down Expand Up @@ -721,7 +721,7 @@ changes:
process will be killed. **Default:** `'SIGTERM'`.
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
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.
**Default:** `'buffer'`.
* `windowsHide` {boolean} Hide the subprocess console window that would
Expand Down Expand Up @@ -788,7 +788,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`.
**Default:** `1024 * 1024`.
* `encoding` {string} The encoding used for all stdio inputs and outputs.
**Default:** `'buffer'`.
* `windowsHide` {boolean} Hide the subprocess console window that would
Expand Down Expand Up @@ -852,7 +852,7 @@ changes:
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is
truncated. See caveat at [`maxBuffer` and Unicode][].
**Default:** `200 * 1024`.
**Default:** `1024 * 1024`.
* `encoding` {string} The encoding used for all stdio inputs and outputs.
**Default:** `'buffer'`.
* `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses
Expand Down
2 changes: 1 addition & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const {
ChildProcess
} = child_process;

const MAX_BUFFER = 200 * 1024;
const MAX_BUFFER = 1024 * 1024;

exports.ChildProcess = ChildProcess;

Expand Down
21 changes: 14 additions & 7 deletions test/parallel/test-child-process-exec-maxbuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function runChecks(err, stdio, streamName, expected) {

// 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) => {
assert(err instanceof RangeError);
Expand All @@ -24,11 +25,11 @@ function runChecks(err, stdio, streamName, expected) {
// default value
{
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) => {
assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1));
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
}));
}
Expand Down Expand Up @@ -58,24 +59,30 @@ function runChecks(err, stdio, streamName, expected) {

// 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, stdout, stderr) => {
runChecks(err, { stdout, stderr }, 'stdout', 'a'.repeat(200 * 1024));
runChecks(
err,
{ stdout, stderr },
'stdout',
'a'.repeat(1024 * 1024)
);
})
);
}

// default value
{
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) => {
assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1));
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
}));
}
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-child-process-execfile-maxbuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function checkFactory(streamName) {
{
execFile(
process.execPath,
['-e', 'console.log("a".repeat(200 * 1024))'],
['-e', 'console.log("a".repeat(1024 * 1024))'],
checkFactory('stdout')
);
}
Expand All @@ -24,10 +24,10 @@ function checkFactory(streamName) {
{
execFile(
process.execPath,
['-e', 'console.log("a".repeat(200 * 1024 - 1))'],
['-e', 'console.log("a".repeat(1024 * 1024 - 1))'],
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
assert.strictEqual(stdout.trim(), 'a'.repeat(200 * 1024 - 1));
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
})
);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-execfilesync-maxBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf);
}

// Default maxBuffer size is 200 * 1024.
// Default maxBuffer size is 1024 * 1024.
{
assert.throws(() => {
execFileSync(
process.execPath,
['-e', "console.log('a'.repeat(200 * 1024))"]
['-e', "console.log('a'.repeat(1024 * 1024))"]
);
}, (e) => {
assert.ok(e, 'maxBuffer should error');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-execfilesync-maxbuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf);
}

// maxBuffer size is 200 * 1024 at default.
// maxBuffer size is 1024 * 1024 at default.
{
assert.throws(
() => {
execFileSync(
process.execPath,
['-e', "console.log('a'.repeat(200 * 1024))"],
['-e', "console.log('a'.repeat(1024 * 1024))"],
{ encoding: 'utf-8' }
);
}, (e) => {
Expand Down
15 changes: 10 additions & 5 deletions test/parallel/test-child-process-execsync-maxbuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@ const args = [
assert.deepStrictEqual(ret, msgOutBuf);
}

// Default maxBuffer size is 200 * 1024.
// Default maxBuffer size is 1024 * 1024.
{
assert.throws(() => {
execSync(`"${process.execPath}" -e "console.log('a'.repeat(200 * 1024))"`);
execSync(
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024))"`
);
}, (e) => {
assert.ok(e, 'maxBuffer should error');
assert.strictEqual(e.errno, 'ENOBUFS');
return true;
});
}

// Default maxBuffer size is 200 * 1024.
// Default maxBuffer size is 1024 * 1024.
{
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)
);
}
10 changes: 5 additions & 5 deletions test/parallel/test-child-process-spawnsync-maxbuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ const args = [
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);

assert.ok(ret.error, 'maxBuffer should error');
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);

assert.ifError(ret.error);
assert.deepStrictEqual(
ret.stdout.toString().trim(),
'a'.repeat(200 * 1024 - 1)
'a'.repeat(1024 * 1024 - 1)
);
}

0 comments on commit 652877e

Please sign in to comment.