Skip to content
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

Merged
merged 2 commits into from
Jan 17, 2017
Merged

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jan 12, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

child_process

Closes #10767

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. dont-land-on-v7.x labels Jan 12, 2017
@sam-github
Copy link
Contributor

+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.

@sam-github sam-github added the semver-minor PRs that contain new features and should be released in the next minor version. label Jan 12, 2017
fail('maxBuffer', -1, err);
fail('maxBuffer', NaN, err);
fail('maxBuffer', Infinity, err);
fail('maxBuffer', true, err);
fail('maxBuffer', false, err);
fail('maxBuffer', __dirname, err);
Copy link
Member

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();
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@mscdex
Copy link
Contributor

mscdex commented Jan 12, 2017

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');

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).

Copy link
Member

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

Copy link
Contributor Author

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');
Copy link
Member

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

@cjihrig cjihrig added semver-major PRs that contain breaking changes and should be released in the next major version. and removed semver-minor PRs that contain new features and should be released in the next minor version. labels Jan 13, 2017
@mscdex
Copy link
Contributor

mscdex commented Jan 13, 2017

Instead of "non-negative", can we use "positive"?

@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 13, 2017

But zero is an allowed, non-positive value.

@mscdex
Copy link
Contributor

mscdex commented Jan 13, 2017

It depends on which zero you're talking about ;-)

@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 13, 2017

Ha. Ok, I'll make it just "positive"

@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 16, 2017

@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 16, 2017

Another CI run because Windows: https://ci.nodejs.org/job/node-test-pull-request/5891/

@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 17, 2017

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 cjihrig merged commit 5b30c4f into nodejs:master Jan 17, 2017
@cjihrig cjihrig deleted the 10767 branch January 17, 2017 15:52
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
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]>
@jasnell jasnell mentioned this pull request Apr 4, 2017
@sam-github
Copy link
Contributor

@cjihrig why is this semver-major? Is it because you added validation for some args?

@cjihrig
Copy link
Contributor Author

cjihrig commented Apr 12, 2017

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants