-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
doc: add comments about Readable unpipe on Writable error event in stream.md #18080
Conversation
Hi, thanks for the PR! You edited the section for stream implementors that tells them how to report errors; I think this would be better kept in the section about |
Do you think it should be in Readable.pipe() section? It seems to me it affects the Writable stream implementers more since right now it is not clear what happens when Writable emits errors. Maybe it should be in both or there should some kind of a reference between the sections? I've improved the wording to make it clearer which stream emits an error. |
doc/api/stream.md
Outdated
@@ -1508,6 +1508,9 @@ the callback and passing the error as the first argument. This will cause an | |||
on how the stream is being used. Using the callback ensures consistent and | |||
predictable handling of errors. | |||
|
|||
*Note*: If a Readable stream pipes into a Writable stream when Writable emits an |
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.
Nit: Consider removing *Note*:
and letting the sentence stand on its own?
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.
This seems like something that requires special attention when implementing error handling in Writable streams and STYLE_GUIDE.md
recommends to mark such things with a *Note*:
.
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 should probably be updated as well. We try to minimize those because they became to frequent and therefore lost there meaning.
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've removed the *Note*
.
doc/api/stream.md
Outdated
@@ -1508,6 +1508,9 @@ the callback and passing the error as the first argument. This will cause an | |||
on how the stream is being used. Using the callback ensures consistent and | |||
predictable handling of errors. | |||
|
|||
*Note*: If a Readable stream pipes into a Writable stream when Writable emits an | |||
error, Readable stream will be unpiped. |
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.
Nit: add the
before Readable stream
.
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.
Done.
I agree with @addaleax that it should be moved to the pipe part. |
@BridgeAR why would this be in the Writable |
@GeorgeSapkin yes Something like e.g. might fit?
@mcollina PTAL |
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.
LGTM
I think we should really add the sentence in 2-3 places. It's one of the most forgotten (and bad) features of streams. I would also note that calling |
Can you add a sentence about the fact |
Ping @GeorgeSapkin |
@mcollina I'm not sure I understand where the note about streams not being closed on |
@GeorgeSapkin the main reason is that a stream is typically holding on to some native resources. A file descriptor, or some other native data. If an error happen and the destination stream is unpiped, the underlining native resource is not freed, and will trigger a memory (or file descriptor) leak. |
I would say we can land this as is (it already improves the current situation) and we have a follow up PR that addresses your comment @mcollina ? |
👍 |
Landed in 1d19fd3 |
PR-URL: #18080 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#18080 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#18080 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#18080 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Documenting Readable unpiping behavior according to: https://github.com/nodejs/node/blob/v8.x/lib/_stream_readable.js#L656-L664
Checklist
Affected core subsystem(s)
doc