-
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
stream: finished should invoke callback for closed streams #31509
Conversation
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.
Can you add a few tests with autoDestroy: false
and autoClose: false
? I know these are edge/possibly legacy cases in v14, but it's important we document that behavior as well.
@mcollina: good call, updated |
I don't know. In my opinion passing an already "finished" stream to |
I think throwing would be bad for usability, I would rather call the callback with an error. I'm ok in both erroring or not erroring as long as something happens. |
I’m good with send error into callback as well. @mcollina that would break some existing use cases, such as the one in your revert PR, i.e. Async iterating a destroyed stream. |
Though it would make things more difficult. Because we have to distinguish between a closed and a closing stream. Not sure that is possible in a safe way considering compat. |
I think throwing is the right thing to do from an API consistency and logical point of view but I'm fine either way. It doesn't make much sense to me to pass an already "finished" stream to |
The problem is that it's quite difficult currently for users to determine whether a stream is "finished" and what that exactly means. Though I agree some kind of error would be better but I think it's a bit more complicated and therefore I would prefer to land this PR as is. My understanding is that neither of you are opposed to this? |
I’m not opposed. |
Rebased to fix conflict. |
@mcollina Does this mean your change request can be cleared? |
Removing |
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 can't reproduce the async-wrap issue on MacOS.
Seems to fail on Debian. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
CI passes |
spawn-wrap flaky issue #31596 |
@Trott: Opinon on CITGM? Can this land? |
CITGM looks OK (but this needs a rebase....) |
Previously finished(stream, cb) would not invoke the callback for streams that have already finished, ended or errored before being passed to finished(stream, cb).
rebased |
Previously finished(stream, cb) would not invoke the callback for streams that have already finished, ended or errored before being passed to finished(stream, cb). PR-URL: #31509 Refs: #31508 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Landed in d016b9d |
const onlegacyfinish = () => { | ||
if (!stream.writable) onfinish(); | ||
}; | ||
|
||
let writableFinished = stream.writableFinished || | ||
(stream._writableState && stream._writableState.finished); | ||
(rState && rState.finished); |
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.
Looks like wState
should be here instead of rState
nodejs#31509 introduced a slight typo. Fortunately this typo does not have big impact due to `isWritableFinished()`. Fixes: nodejs#31509 (comment)
#31509 introduced a slight typo. Fortunately this typo does not have big impact due to `isWritableFinished()`. Fixes: #31509 (comment) PR-URL: #31881 Fixes: #31509 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Previously finished(stream, cb) would not invoke the callback for streams
that have already finished, ended or errored before being
passed to finished(stream, cb).
Ref: #31508
Ref: #31314 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes