Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
stream: pipeline don't destroy Duplex src before 'finish'#32966
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
ronag commented Apr 21, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
fcb17b5 to 229f5d2Comparepipeline was too agressive with destroying Duplex streams which were the first argument into pipeline. Just because it's !writable does not mean that it is safe to be destroyed, unless it has also emitted 'finish'. Fixes: nodejs#32955
lib/internal/streams/pipeline.js Outdated
| constwState=stream._writableState; | ||
| constwritableEnded=stream.writableEnded|| | ||
| (wState&&wState.ended); | ||
| constwritableFinished=stream.writableFinished|| | ||
| (wState&&wState.finished); | ||
| constwillFinish=stream.writable|| | ||
| (writableEnded&&!writableFinished); | ||
| constwillEnd=stream.readable; | ||
| if(err||!final||!stream.readable){ | ||
| destroyImpl.destroyer(stream,err); | ||
| if(!err){ | ||
| // First | ||
| if(reading&&!writing&&willFinish){ | ||
| returncallback(); | ||
| } | ||
| // Last | ||
| if(!reading&&writing&&willEnd){ | ||
| returncallback(); | ||
| } |
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: it is possible to reduce the code branches a bit:
| constwState=stream._writableState; | |
| constwritableEnded=stream.writableEnded|| | |
| (wState&&wState.ended); | |
| constwritableFinished=stream.writableFinished|| | |
| (wState&&wState.finished); | |
| constwillFinish=stream.writable|| | |
| (writableEnded&&!writableFinished); | |
| constwillEnd=stream.readable; | |
| if(err||!final||!stream.readable){ | |
| destroyImpl.destroyer(stream,err); | |
| if(!err){ | |
| // First | |
| if(reading&&!writing&&willFinish){ | |
| returncallback(); | |
| } | |
| // Last | |
| if(!reading&&writing&&willEnd){ | |
| returncallback(); | |
| } | |
| if(!err){ | |
| // Check if the last stream will end: | |
| if(!reading){ | |
| if(writing&&stream.readable){ | |
| returncallback(); | |
| } | |
| // First stream | |
| }elseif(!writing){ | |
| if(stream.writable){ | |
| returncallback(); | |
| } | |
| constwState=stream._writableState; | |
| constwritableEnded=stream.writableEnded|| | |
| (wState&&wState.ended); | |
| constwritableFinished=stream.writableFinished|| | |
| (wState&&wState.finished); | |
| if(writableEnded&&!writableFinished) | |
| returncallback(); | |
| } | |
| } |
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.
@BridgeAR: Any specific reason? This does make it a bit harder to read in my opinon.
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.
Code should IMO always only run when necessary. Right now some code is executed that is only needed in some situations.
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 is not a hot path so readability should IMO come first. I think I can make a compromise 😄. PTAL.
| destroyImpl.destroyer(stream,err); | ||
| if(!err){ | ||
| // First | ||
| if(reading&&!writing&&willFinish){ |
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 willFinish part here is the significant change. Before we only checked stream.writable.
The rest of the changes should be logically the same.
ronag commented Apr 21, 2020
blocked pending #32954 |
ronag commented Apr 21, 2020
closed in favor of #32968 |
pipeline was too agressive with destroying Duplex
streams which were the first argument into pipeline.
Just because it's !writable does not mean that it
is safe to be destroyed, unless it has also emitted
'finish'.
Fixes: #32955
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes