From 652877e3a9eee3f863314382f64f8ac1e5b27186 Mon Sep 17 00:00:00 2001 From: kohta ito Date: Thu, 11 Apr 2019 03:26:58 +0900 Subject: [PATCH] child_process: change the defaults maxBuffer size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/27179 Refs: https://github.com/nodejs/node/pull/23027 Reviewed-By: Ben Noordhuis Reviewed-By: Sam Roberts Reviewed-By: Ruben Bridgewater Reviewed-By: Michaƫl Zasso Reviewed-By: Beth Griggs Reviewed-By: Michael Dawson --- doc/api/child_process.md | 10 ++++----- lib/child_process.js | 2 +- .../test-child-process-exec-maxbuf.js | 21 ++++++++++++------- .../test-child-process-execfile-maxbuf.js | 6 +++--- ...st-child-process-execfilesync-maxBuffer.js | 4 ++-- .../test-child-process-execfilesync-maxbuf.js | 4 ++-- .../test-child-process-execsync-maxbuf.js | 15 ++++++++----- .../test-child-process-spawnsync-maxbuf.js | 10 ++++----- 8 files changed, 42 insertions(+), 30 deletions(-) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index b2208c006ccaeb..b3c9d10250f759 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -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)). @@ -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)). @@ -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 @@ -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 @@ -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 diff --git a/lib/child_process.js b/lib/child_process.js index f60950486d859a..64ab321f295f5d 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -49,7 +49,7 @@ const { ChildProcess } = child_process; -const MAX_BUFFER = 200 * 1024; +const MAX_BUFFER = 1024 * 1024; exports.ChildProcess = ChildProcess; diff --git a/test/parallel/test-child-process-exec-maxbuf.js b/test/parallel/test-child-process-exec-maxbuf.js index 2291227b5ef2b4..0f639b5dd90e1d 100644 --- a/test/parallel/test-child-process-exec-maxbuf.js +++ b/test/parallel/test-child-process-exec-maxbuf.js @@ -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); @@ -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, ''); })); } @@ -58,12 +59,18 @@ 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) + ); }) ); } @@ -71,11 +78,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, ''); })); } diff --git a/test/parallel/test-child-process-execfile-maxbuf.js b/test/parallel/test-child-process-execfile-maxbuf.js index ba074630a14a6b..8cc9b95d374367 100644 --- a/test/parallel/test-child-process-execfile-maxbuf.js +++ b/test/parallel/test-child-process-execfile-maxbuf.js @@ -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') ); } @@ -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, ''); }) ); diff --git a/test/parallel/test-child-process-execfilesync-maxBuffer.js b/test/parallel/test-child-process-execfilesync-maxBuffer.js index 2145849f0a5c9f..d4bed07d06030a 100644 --- a/test/parallel/test-child-process-execfilesync-maxBuffer.js +++ b/test/parallel/test-child-process-execfilesync-maxBuffer.js @@ -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'); diff --git a/test/parallel/test-child-process-execfilesync-maxbuf.js b/test/parallel/test-child-process-execfilesync-maxbuf.js index 8b576654a1fd07..2ec0489358b5ed 100644 --- a/test/parallel/test-child-process-execfilesync-maxbuf.js +++ b/test/parallel/test-child-process-execfilesync-maxbuf.js @@ -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) => { diff --git a/test/parallel/test-child-process-execsync-maxbuf.js b/test/parallel/test-child-process-execsync-maxbuf.js index 67ccf0c7bb9d47..6400c49b028230 100644 --- a/test/parallel/test-child-process-execsync-maxbuf.js +++ b/test/parallel/test-child-process-execsync-maxbuf.js @@ -38,10 +38,12 @@ 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'); @@ -49,11 +51,14 @@ const args = [ }); } -// 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) + ); } diff --git a/test/parallel/test-child-process-spawnsync-maxbuf.js b/test/parallel/test-child-process-spawnsync-maxbuf.js index 0808dfd56f4b24..5f4e959b880d4b 100644 --- a/test/parallel/test-child-process-spawnsync-maxbuf.js +++ b/test/parallel/test-child-process-spawnsync-maxbuf.js @@ -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) ); }