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

stream: check type and range of highWaterMark #13065

Closed
wants to merge 3 commits into from

Conversation

tniessen
Copy link
Member

Adds checks for the type of "highWaterMark" and restricts it to non-negative values as suggested here by @mscdex.

Refs: #12593

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)

stream

Adds checks for the type of "highWaterMark" and restricts it to
non-negative values.

Refs: nodejs#12593
@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label May 16, 2017
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
if (hwm == null) {
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
this.highWaterMark = defaultHwm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just move the ternary to here instead?

Copy link
Member Author

@tniessen tniessen May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I wanted to, but I think I got an opposing comment when I did the same in one of the first commits of #12593. I cannot find it though, so I will go ahead and change it.

Edit: Done.

this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
if (hwm == null) {
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
this.highWaterMark = defaultHwm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 19, 2017
@mcollina
Copy link
Member

I am 👎 in shipping this for v8.0.0, as it will require a major bump of readable-streamas well.
cc @calvinmetcalf what do you think?

@mscdex
Copy link
Contributor

mscdex commented May 19, 2017

FWIW this PR is definitely supposed to be semver-major. As for which major version it gets shipped with, I don't particularly have any opinion on it.

@tniessen
Copy link
Member Author

Deciding whether and when to include this patch is entirely up to you, I just thought it was consensus that it should be implemented at some point.

@mcollina
Copy link
Member

@tniessen there is consensus that is needed :). I don't think we are ready to bump readable-stream major right now.

@calvinmetcalf
Copy link
Contributor

I'm super against bumping readable-stream just on the grounds that nobody is going to upgrade anytime soon, we should at least put in a warning first and see how many people complain

@jasnell
Copy link
Member

jasnell commented May 22, 2017

At this point it wouldn't make it in time for 8.0.0 anyway (which comes out in just over a week). I'm going to be pulling some semver-majors in either later today or tomorrow but I'm going to be very selective about it.

@jasnell jasnell added this to the 9.0.0 milestone May 22, 2017
@tniessen
Copy link
Member Author

tniessen commented Jun 1, 2017

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM just a few nits.

throw new RangeError('"highWaterMark" must not be negative');
}

// cast to ints.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it's better to start a comment with upper case. The same in the other file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a remainder from the old code.


// cast to ints.
this.highWaterMark = Math.floor(hwm);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to move this part into a generic function that can be called by readable and writable stream to prevent code duplication. This also keeps it always in line as the limits stay the same in both cases.

// cast to ints.
this.highWaterMark = Math.floor(this.highWaterMark);
if (hwm < 0) {
throw new RangeError('"highWaterMark" must not be negative');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the internal error types would be used for all new errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually the case for streams. It's a way bigger chunk of work that we need to do, as we would have to support them in readable-stream as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the update 👍

@calvinmetcalf
Copy link
Contributor

so my current inclination is that this is not worth a major bump of readable-streams by itself

@BridgeAR
Copy link
Member

@calvinmetcalf do you think this could land in 9.0.0?

@mcollina
Copy link
Member

I am 👎 on landing this on 9.

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

@mcollina ... is that a -1 to landing this at all or just right now?

@mcollina
Copy link
Member

right now. I'm +1 on the change on itself.

@BridgeAR BridgeAR added the blocked PRs that are blocked by other issues or PRs. label Aug 29, 2017
@BridgeAR
Copy link
Member

I added the blocked label. I guess as soon as streams get the next major there will be a couple PRs for it.

@tniessen
Copy link
Member Author

I will do the rebase, address the nits etc. once the streams WG (namely @mcollina) decides when to ship this.

@targos targos modified the milestones: 9.0.0, 10.0.0 Oct 23, 2017
@BridgeAR
Copy link
Member

@mcollina are you fine with landing this on v10? In that case it could be continued.

@mcollina
Copy link
Member

mcollina commented Dec 8, 2017

I think we should, but I would like to keep thinking about it a bit more. Can we leave it as is?

@BridgeAR
Copy link
Member

@mcollina as far as I know we land a couple of stream changes at the moment that might be breaking, so I personally feel like it is the right time to land this as well.

@mcollina
Copy link
Member

mcollina commented Jan 8, 2018

I'm 👍 with this change in Node 10.

Anyone against this? cc @nodejs/streams

@mcollina
Copy link
Member

mcollina commented Jan 8, 2018

Can you update the errors to use the new error codes? Those are supported in streams now.

@tniessen
Copy link
Member Author

Closing this in favor of #18098.

@tniessen tniessen closed this Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. semver-major PRs that contain breaking changes and should be released in the next major version. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants