-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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: emit .write() end error in next tick #4749
Conversation
process.nextTick(cb, er); | ||
function writeAfterEndErr(stream, cb) { | ||
const err = new Error('write after end'); | ||
process.nextTick(() => stream.emit('error', 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.
It would probably be better to just call process.nextTick
once here and both emit the error and call the callback.
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.
I agree.
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.
It would probably be better to just call process.nextTick once here and both emit the error and call the callback.
Sure thing, agreed it looked strange. Just pushed an update.
Generally LGTM once @evanlucas, @mscdex and CI are happy :-) |
Marking as semver-major as it is a behavior change |
@nodejs/streams |
b732435
to
227c9f5
Compare
227c9f5
to
76f6165
Compare
process.nextTick(() => { | ||
stream.emit('error', err); | ||
cb(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.
i'm not sure we transform arrow functions yet in the readable-stream builds. @calvinmetcalf probably knows more about this?
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.
i'm not sure we transform arrow functions yet in the readable-stream builds.
I'll happily change it to an ordinary function. Really curious about what kind of transformation you're talking about though?
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.
the readable-stream module is build from the node source using a couple of build methods, https://github.com/nodejs/readable-stream/tree/master/build to get better browser support.
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.
we do not support arrow functions at the moment, and it would be tricky to do so in a performant manner, that being said, you could change this code to be,
function writeAfterEnd(stream, cb) {
const err = new Error('write after end');
stream.emit('error', err);
cb(err);
}
and then replace the use of writeAfterEndErr(this, cb) with
process.nextTick(writeAfterEnd, this, cb);
and this would avoid creating an unnecessary closure
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.
the readable-stream module is build from the node source using a couple of build methods, https://github.com/nodejs/readable-stream/tree/master/build to get better browser support.
Neat, that's some nice wizardry.
and then replace the use of writeAfterEndErr(this, cb) with
Thanks @calvinmetcalf, just pushed an update 👍
I worry about this a little, in that streams can be enormously fussy when it comes to when things happen. A CITGM run with this would ease my mind a bit (especially if CITGM contains stream-using packages, like |
@chrisdickinson can you make a short list of stream based packages you would like to see added to citgm? I'd be more than happy to add them then run the smoke-testing suite |
current lookup for reference --> https://github.com/nodejs/citgm/blob/master/lib/lookup.json |
This changes the behaviour of error event emitted when writing to a stream after it has ended, from synchronously to asynchronously. PR-URL: nodejs#4749
76f6165
to
1899689
Compare
I just created these citgm reports @chrisdickinson: This PRFlaky Modules
v4.2.5Flaky Modules
v5.5.0Flaky Modules
P.S. react fails deliberately as it requires v4.x obviously. |
Unfortunately I think failures on those in citgm are common. @thealphanerd can say for sure tho |
Those are all expected 😄 |
fwiw I think @chrisdickinson wanted to add more modules to citgm that were focused on streams. |
I might see if @phated can recommend some modules from the Gulp ecosystem. |
@chrisdickinson what are you looking for? |
@phated ... we'd like to get a handful of stream-related modules to add to our smoke-testing infrastructure (http://github.com/nodejs/citgm). We run the tests for every new release and to get an idea of whether a particular change will break the ecosystem. |
vinyl, vinyl-fs, probably something like gulp-jade or other popular plugins (I don't have actual numbers on any of that) The most important one is probably vinyl-fs which will be receiving even more tests coming up very soon. |
@phated... excellent. /cc @thealphanerd |
I've opened a PR adding vinyl, vinyl-fs, and readable-stream to citgm. I'm open to other suggestions |
Updated results after mentioned updates to citgm ^^ Flaky Modules
Identical results ran on master and this branch/PR, in other words doesn't seem like this PR introduces more failures.. @thealphanerd is the spdy failure expected? |
FWIW, still LGTM /cc @nodejs/ctc |
Actually.. looks like this change is also applied in #5251 ... may be able to close this in favor of that one |
Yep, surely looks like we've done some duplicate work on this one. As #5251 fixes alot more of these issues, I'll close this one and re-open if the other one doesn't land. |
Next up in my TODO triaging, this time in _stream_writable.js.
Assuming it should be labelled semver-major as it changes from emitting error synchronously to async.