stream: improving error handling by mafintosh · Pull Request #18438 · nodejs/node (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation59 Commits15 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes- tests and/or benchmarks are included
- documentation is changed or added
- commit message follows commit guidelines
Affected core subsystem(s)
stream
This PR improves error handling for streams in a few ways.
- It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called.
- It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed.
- It makes streams always emit
close
as the last thing after they have been destroyed - Changes the default _destroy to not gracefully end streams.
Especially 4. makes it easier for userland modules to handle stream errors as they don't appear as graceful closes anymore. Seen issues being with end-of-stream/pump because of this.
### ERR_STREAM_DESTROYED |
An stream method was called that cannot complete cause the stream was been |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits:
An stream -> A stream
was been -> has been
@@ -106,6 +106,9 @@ function ReadableState(options, stream) { |
---|
this.readableListening = false; |
this.resumeScheduled = false; |
// True if the close was already emitted and should not emitted again |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit: should not emitted -> should not be emitted
@@ -134,6 +134,9 @@ function WritableState(options, stream) { |
---|
// True if the error was already emitted and should not be thrown again |
this.errorEmitted = false; |
// True if the close was already emitted and should not emitted again |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit: should not emitted -> should not be emitted
@nodejs/http2 ... just a quick note that this will have a relatively small impact on the 'close'
event currently emitted for Http2Stream
and Http2Session
.
Added docs about the close
event and the ERR_STREAM_DESTROYED
error.
Issues and PRs related to the stream subsystem.
PRs that contain breaking changes and should be released in the next major version.
and removed lib / src
Issues and PRs related to general changes in the lib or src directory.
labels
// Set close emitted, so the stream destruction does not |
---|
// emit them |
this._readableState.closeEmitted = true; |
this._writableState.closeEmitted = true; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very fond of this lines. A current goal is to reduce (or totally remove) the number of access to _readableState
and _writableState
. However, this requires it. Maybe emitting 'close'
automatically can be moved to an option?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only because http2 currently emits a 'code' argument with the close event. The idea is to get rid of that in http2 and move the 'code' to a property down the line, but this ensures backwards compat right now.
Should I add a comment explaining that?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that in both fs
and http2
for compat reason we need to not emit 'close'
on destroy. I think this might actually be a legit use case, and so we should support it with an option at construction.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fs
thing is legit, but we should just get rid of the code in http2
imo, but that's another discussion. I like the idea of an option, adding it.
@@ -437,7 +441,8 @@ Readable.prototype.read = function(n) { |
---|
if (state.length === 0) |
state.needReadable = true; |
// call internal read method |
this._read(state.highWaterMark); |
if (!state.destroyed) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check can me moved in the previous if
block: state.ended || state.reading || state.destroyed
.
@@ -132,6 +132,8 @@ function Transform(options) { |
---|
} |
function prefinish() { |
if (this._readableState.destroyed) |
return; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add one more test for the _flush()
logic and destroy()
? It seems you are fixing a bug here. Or without this change some tests would not pass anymore?
Issues and PRs related to the fs subsystem / file system.
Issues or PRs related to the http2 subsystem.
labels
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a nit
@@ -219,6 +226,11 @@ function Socket(options) { |
---|
options = { fd: options }; // Legacy interface. |
else if (options === undefined) |
options = {}; |
else |
options = copyObject(options); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Object.assign
.
mafintosh changed the title
Improving streams error handling stream: improving error handling
@mafintosh can you add emitClose
to the documented options?
### ERR_STREAM_DESTROYED |
A stream method was called that cannot complete cause the stream was been |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like cause
should be because
here, I think?
### ERR_STREAM_DESTROYED |
A stream method was called that cannot complete cause the stream was been |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/cause/because
We are testing in so many system that a botched run happens every now and then.
mcollina pushed a commit that referenced this pull request
This improves error handling for streams in a few ways.
- It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called.
- It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed.
- It makes streams always emit close as the last thing after they have been destroyed
- Changes the default _destroy to not gracefully end streams.
It also updates net, http2, zlib and fs to the new error handling.
PR-URL: #18438 Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Anna Henningsen anna@addaleax.net
mafintosh deleted the streams-error-handling-fix branch
mcollina added a commit to mcollina/node that referenced this pull request
mcollina added a commit that referenced this pull request
See: #18438
PR-URL: #19169 Reviewed-By: Joyee Cheung joyeec9h3@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request
This improves error handling for streams in a few ways.
- It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called.
- It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed.
- It makes streams always emit close as the last thing after they have been destroyed
- Changes the default _destroy to not gracefully end streams.
It also updates net, http2, zlib and fs to the new error handling.
PR-URL: nodejs#18438 Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Anna Henningsen anna@addaleax.net
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request
See: nodejs#18438
PR-URL: nodejs#19169 Reviewed-By: Joyee Cheung joyeec9h3@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de
kjin mentioned this pull request
3 tasks
mcollina added a commit to mcollina/node that referenced this pull request
mcollina added a commit that referenced this pull request
PR-URL: #25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
addaleax pushed a commit that referenced this pull request
PR-URL: #25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request
See: nodejs#25373 See: nodejs#18438
PR-URL: nodejs#25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
BethGriggs pushed a commit that referenced this pull request
PR-URL: #25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
BethGriggs pushed a commit that referenced this pull request
PR-URL: #25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
MylesBorins pushed a commit that referenced this pull request
PR-URL: #25413 Reviewed-By: Richard Lau riclau@uk.ibm.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Sam Roberts vieuxtech@gmail.com
Reviewers
Trott Trott left review comments
lpinca lpinca left review comments
cjihrig cjihrig left review comments
vsemozhetbyt vsemozhetbyt left review comments
mcollina mcollina approved these changes
jasnell jasnell approved these changes
addaleax addaleax approved these changes
BridgeAR BridgeAR approved these changes
joyeecheung Awaiting requested review from joyeecheung
Labels
Issues and PRs related to the fs subsystem / file system.
Issues or PRs related to the http2 subsystem.
PRs that contain breaking changes and should be released in the next major version.
Issues and PRs related to the stream subsystem.