Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd05b0b

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
Revert "child_process: measure buffer length in bytes"
This reverts commit c9a5990. PR-URL: #7391 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
1 parent a31d316 commit fd05b0b
Copy full SHA for fd05b0b

File tree

Expand file treeCollapse file tree

4 files changed

+32
-57
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+32
-57
lines changed
Open diff view settings
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+30-41Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ exports.execFile = function(file /*, args, options, callback*/) {
157157
});
158158

159159
var encoding;
160-
var stdoutState;
161-
var stderrState;
162-
var _stdout = [];
163-
var _stderr = [];
160+
var _stdout;
161+
var _stderr;
164162
if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) {
165163
encoding = options.encoding;
164+
_stdout = '';
165+
_stderr = '';
166166
} else {
167+
_stdout = [];
168+
_stderr = [];
167169
encoding = null;
168170
}
169171
var stdoutLen = 0;
@@ -185,23 +187,16 @@ exports.execFile = function(file /*, args, options, callback*/) {
185187

186188
if (!callback) return;
187189

188-
var stdout = Buffer.concat(_stdout, stdoutLen);
189-
var stderr = Buffer.concat(_stderr, stderrLen);
190-
191-
var stdoutEncoding = encoding;
192-
var stderrEncoding = encoding;
193-
194-
if (stdoutState && stdoutState.decoder)
195-
stdoutEncoding = stdoutState.decoder.encoding;
196-
197-
if (stderrState && stderrState.decoder)
198-
stderrEncoding = stderrState.decoder.encoding;
199-
200-
if (stdoutEncoding)
201-
stdout = stdout.toString(stdoutEncoding);
202-
203-
if (stderrEncoding)
204-
stderr = stderr.toString(stderrEncoding);
190+
// merge chunks
191+
var stdout;
192+
var stderr;
193+
if (!encoding) {
194+
stdout = Buffer.concat(_stdout);
195+
stderr = Buffer.concat(_stderr);
196+
} else {
197+
stdout = _stdout;
198+
stderr = _stderr;
199+
}
205200

206201
if (ex) {
207202
// Will be handled later
@@ -261,45 +256,39 @@ exports.execFile = function(file /*, args, options, callback*/) {
261256
}
262257

263258
if (child.stdout) {
264-
stdoutState = child.stdout._readableState;
259+
if (encoding)
260+
child.stdout.setEncoding(encoding);
265261

266262
child.stdout.addListener('data', function(chunk) {
267-
// If `child.stdout.setEncoding()` happened in userland, convert string to
268-
// Buffer.
269-
if (stdoutState.decoder) {
270-
chunk = Buffer.from(chunk, stdoutState.decoder.encoding);
271-
}
272-
273-
stdoutLen += chunk.byteLength;
263+
stdoutLen += chunk.length;
274264

275265
if (stdoutLen > options.maxBuffer) {
276266
ex = new Error('stdout maxBuffer exceeded');
277-
stdoutLen -= chunk.byteLength;
278267
kill();
279268
} else {
280-
_stdout.push(chunk);
269+
if (!encoding)
270+
_stdout.push(chunk);
271+
else
272+
_stdout += chunk;
281273
}
282274
});
283275
}
284276

285277
if (child.stderr) {
286-
stderrState = child.stderr._readableState;
278+
if (encoding)
279+
child.stderr.setEncoding(encoding);
287280

288281
child.stderr.addListener('data', function(chunk) {
289-
// If `child.stderr.setEncoding()` happened in userland, convert string to
290-
// Buffer.
291-
if (stderrState.decoder) {
292-
chunk = Buffer.from(chunk, stderrState.decoder.encoding);
293-
}
294-
295-
stderrLen += chunk.byteLength;
282+
stderrLen += chunk.length;
296283

297284
if (stderrLen > options.maxBuffer) {
298285
ex = new Error('stderr maxBuffer exceeded');
299-
stderrLen -= chunk.byteLength;
300286
kill();
301287
} else {
302-
_stderr.push(chunk);
288+
if (!encoding)
289+
_stderr.push(chunk);
290+
else
291+
_stderr += chunk;
303292
}
304293
});
305294
}
Collapse file

‎…l/test-child-process-maxBuffer-stdout.js‎ ‎…_issues/test-child-process-max-buffer.js‎test/parallel/test-child-process-maxBuffer-stdout.js renamed to test/known_issues/test-child-process-max-buffer.js test/parallel/test-child-process-maxBuffer-stdout.js renamed to test/known_issues/test-child-process-max-buffer.js

Copy file name to clipboardExpand all lines: test/known_issues/test-child-process-max-buffer.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
// Refs: https://github.com/nodejs/node/issues/1901
23
const common = require('../common');
34
const assert = require('assert');
45
const cp = require('child_process');
@@ -9,7 +10,7 @@ if (process.argv[2] === 'child') {
910
} else {
1011
const cmd = `${process.execPath} ${__filename} child`;
1112

12-
cp.exec(cmd, {maxBuffer: 10}, common.mustCall((err, stdout, stderr) => {
13+
cp.exec(cmd, { maxBuffer: 10 }, common.mustCall((err, stdout, stderr) => {
1314
assert.strictEqual(err.message, 'stdout maxBuffer exceeded');
1415
}));
1516
}
Collapse file

‎…child-process-exec-stdout-data-string.js‎ ‎…child-process-exec-stdout-data-string.js‎test/known_issues/test-child-process-exec-stdout-data-string.js renamed to test/parallel/test-child-process-exec-stdout-data-string.js test/known_issues/test-child-process-exec-stdout-data-string.js renamed to test/parallel/test-child-process-exec-stdout-data-string.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎test/parallel/test-child-process-maxBuffer-stderr.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-maxBuffer-stderr.js
-15Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.