-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process: allow Infinity as maxBuffer value #10769
Conversation
+1 for feature, but needs docs and tests across all child_process APIs that support maxBuffer. Doesn't have to test that the behaviour is unlimited, but should test that it doesn't abort or throw arg typerrors. |
fail('maxBuffer', -1, err); | ||
fail('maxBuffer', NaN, err); | ||
fail('maxBuffer', Infinity, err); | ||
fail('maxBuffer', true, err); | ||
fail('maxBuffer', false, err); | ||
fail('maxBuffer', __dirname, err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps include a fail
test for -Infinity
CHECK(js_max_buffer->IsUint32()); | ||
max_buffer_ = js_max_buffer->Uint32Value(); | ||
CHECK(js_max_buffer->IsNumber()); | ||
max_buffer_ = js_max_buffer->NumberValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm not sure that JavaScript Infinity will convert to C++ properly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so JavaScript Infinity
translates to std::numeric_limits<double>::infinity()
in C++. So, I changed max_buffer_
to a double.
For consistency, we should probably add the same conditionals to the async counterparts. |
@@ -473,7 +473,7 @@ function spawnSync(/*file, args, options*/) { | |||
|
|||
// Validate maxBuffer, if present. | |||
if (options.maxBuffer != null && | |||
!(Number.isInteger(options.maxBuffer) && options.maxBuffer >= 0)) { | |||
!(typeof options.maxBuffer === 'number' && options.maxBuffer >= 0)) { | |||
throw new TypeError('"maxBuffer" must be an unsigned integer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message needs to be updated to reflect the new constraint (It now accepts any positive number, not just unsigned integer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. The integer check is still required otherwise we'll have nonsense things like 0.1
accepted as the maxBuffer. The check should likely be something like:
if ((Number.isInteger(options.maxBuffer) || options.maxBuffer === Infinity) &&
options.maxBuffer >= 0) {
...
}
And the error message should certainly be updated but that would upgrade this to a semver-major change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.1 is technically fine as a maxBuffer
value, even if it is a bit weird. We're just going to be doing comparisons against the value to see if we surpass it.
And the error message should certainly be updated but that would upgrade this to a semver-major change
This builds on an existing semver major change, so this is going to be semver major regardless.
@@ -473,7 +473,7 @@ function spawnSync(/*file, args, options*/) { | |||
|
|||
// Validate maxBuffer, if present. | |||
if (options.maxBuffer != null && | |||
!(Number.isInteger(options.maxBuffer) && options.maxBuffer >= 0)) { | |||
!(typeof options.maxBuffer === 'number' && options.maxBuffer >= 0)) { | |||
throw new TypeError('"maxBuffer" must be an unsigned integer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. The integer check is still required otherwise we'll have nonsense things like 0.1
accepted as the maxBuffer. The check should likely be something like:
if ((Number.isInteger(options.maxBuffer) || options.maxBuffer === Infinity) &&
options.maxBuffer >= 0) {
...
}
And the error message should certainly be updated but that would upgrade this to a semver-major change
Instead of "non-negative", can we use "positive"? |
But zero is an allowed, non-positive value. |
It depends on which zero you're talking about ;-) |
Ha. Ok, I'll make it just "positive" |
Another CI run because Windows: https://ci.nodejs.org/job/node-test-pull-request/5891/ |
Another CI run: https://ci.nodejs.org/job/node-test-pull-request/5911/ |
Fixes: nodejs#10767 PR-URL: nodejs#10769 Reviewed-By: James M Snell <[email protected]>
This commit refactors test-child-process-spawnsync-maxbuf.js, and adds testing for the case where maxBuffer is Infinity. PR-URL: nodejs#10769 Reviewed-By: James M Snell <[email protected]>
Fixes: nodejs#10767 PR-URL: nodejs#10769 Reviewed-By: James M Snell <[email protected]>
This commit refactors test-child-process-spawnsync-maxbuf.js, and adds testing for the case where maxBuffer is Infinity. PR-URL: nodejs#10769 Reviewed-By: James M Snell <[email protected]>
@cjihrig why is this semver-major? Is it because you added validation for some args? |
Yes. |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
child_process
Closes #10767