GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: pipeline don't destroy Duplex src before 'finish' by ronag · Pull Request #32966 · nodejs/node

Conversation

@ronag

@ronag ronag commented Apr 21, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag ronag added the stream Issues and PRs related to Node.js streams. label Apr 21, 2020
@ronag
ronag requested a review from mafintosh April 21, 2020 10:25
@ronag
ronag force-pushed the pipeline-destroy branch 2 times, most recently from fcb17b5 to 229f5d2 Compare April 21, 2020 10:26
@ronag
stream: pipeline don't destroy Duplex src before 'finish'
e1edd39
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: nodejs#32955
@ronag
ronag force-pushed the pipeline-destroy branch from 229f5d2 to e1edd39 Compare April 21, 2020 10:26
@ronag ronag changed the title stream: pipeline should not destroy Duplex src/dst stream: pipeline don't destroy Duplex src before 'finish' Apr 21, 2020
@ronag ronag added the v13.x label Apr 21, 2020
BridgeAR
BridgeAR reviewed Apr 21, 2020
View reviewed changes
Comment thread lib/internal/streams/pipeline.js Outdated
Comment on lines +53 to +73
const wState = stream._writableState;

const writableEnded = stream.writableEnded ||
(wState && wState.ended);
const writableFinished = stream.writableFinished ||
(wState && wState.finished);

const willFinish = stream.writable ||
(writableEnded && !writableFinished);
const willEnd = stream.readable;

if (err || !final || !stream.readable) {
destroyImpl.destroyer(stream, err);
if (!err) {
// First
if (reading && !writing && willFinish) {
return callback();
}

// Last
if (!reading && writing && willEnd) {
return callback();
}

@BridgeAR BridgeAR Apr 21, 2020

Copy link
Copy Markdown
Member

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:

Suggested change
const wState = stream._writableState;
const writableEnded = stream.writableEnded ||
(wState && wState.ended);
const writableFinished = stream.writableFinished ||
(wState && wState.finished);
const willFinish = stream.writable ||
(writableEnded && !writableFinished);
const willEnd = stream.readable;
if (err || !final || !stream.readable) {
destroyImpl.destroyer(stream, err);
if (!err) {
// First
if (reading && !writing && willFinish) {
return callback();
}
// Last
if (!reading && writing && willEnd) {
return callback();
}
if (!err) {
// Check if the last stream will end:
if (!reading) {
if (writing && stream.readable) {
return callback();
}
// First stream
} else if (!writing) {
if (stream.writable) {
return callback();
}
const wState = stream._writableState;
const writableEnded = stream.writableEnded ||
(wState && wState.ended);
const writableFinished = stream.writableFinished ||
(wState && wState.finished);
if (writableEnded && !writableFinished)
return callback();
}
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ronag ronag Apr 21, 2020

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Apr 21, 2020

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ronag ronag Apr 21, 2020

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag ronag mentioned this pull request Apr 21, 2020
stream: cleanup pipeline destroyer #32690
Closed
4 tasks done
ronag
ronag commented Apr 21, 2020
View reviewed changes
Comment thread lib/internal/streams/pipeline.js
destroyImpl.destroyer(stream, err);
if (!err) {
// First
if (reading && !writing && willFinish) {

@ronag ronag Apr 21, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag
fixup: nit
b58909d
@ronag ronag added the blocked PRs that are blocked by other issues or PRs. label Apr 21, 2020
@ronag

ronag commented Apr 21, 2020

Copy link
Copy Markdown
Member Author

blocked pending #32954

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag

ronag commented Apr 21, 2020

Copy link
Copy Markdown
Member Author

closed in favor of #32968

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag ronag closed this Apr 21, 2020
This was referenced Aug 31, 2021
[Snyk] Security upgrade gatsby from 2.24.27 to 3.13.0 Dmarch28/node#31
Open
[Snyk] Security upgrade gatsby from 2.13.73 to 3.13.0 kissofire/node#41
Open
[Snyk] Security upgrade gatsby from 2.13.73 to 3.13.0 meghasfdc/node#41
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 ron-a20/node#40
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 Rednickle/node-1#27
Open
[Snyk] Security upgrade gatsby from 2.24.27 to 3.13.0 baby636/node#16
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 sitedata/node#31
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 molllyn1/node#20
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 aliceUnhinged613/node#31
Open
This was referenced Sep 12, 2021
[Snyk] Security upgrade gatsby from 2.24.27 to 3.13.0 Dmarch28/node#35
Open
[Snyk] Security upgrade gatsby from 2.24.27 to 3.13.0 baby636/node#20
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 wedataintelligence/node#12
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 137717unity/node#35
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 ron-a20/node#44
Open
@137717unity 137717unity mentioned this pull request Mar 22, 2024
[Snyk] Fix for 2 vulnerabilities 137717unity/node#122
Open
@baby636 baby636 mentioned this pull request Mar 22, 2024
[Snyk] Security upgrade gatsby from 2.24.27 to 3.13.0 baby636/node#136
Open
@kissofire kissofire mentioned this pull request Mar 22, 2024
[Snyk] Fix for 2 vulnerabilities kissofire/node#124
Open
@aliceUnhinged613 aliceUnhinged613 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 2 vulnerabilities aliceUnhinged613/node#123
Open
@ron-a20 ron-a20 mentioned this pull request Mar 22, 2024
[Snyk] Fix for 2 vulnerabilities ron-a20/node#121
Open
@wedataintelligence wedataintelligence mentioned this pull request Mar 23, 2024
[Snyk] Fix for 2 vulnerabilities wedataintelligence/node#105
Open
@aliceUnhinged613 aliceUnhinged613 mentioned this pull request May 13, 2024
[Snyk] Fix for 1 vulnerabilities aliceUnhinged613/node#127
Open
@molllyn1 molllyn1 mentioned this pull request May 13, 2024
[Snyk] Fix for 2 vulnerabilities molllyn1/node#111
Open
@ron-a20 ron-a20 mentioned this pull request May 13, 2024
[Snyk] Fix for 2 vulnerabilities ron-a20/node#126
Open
@kissofire kissofire mentioned this pull request May 13, 2024
[Snyk] Fix for 2 vulnerabilities kissofire/node#128
Open
@137717unity 137717unity mentioned this pull request May 14, 2024
[Snyk] Fix for 2 vulnerabilities 137717unity/node#128
Open
@baby636 baby636 mentioned this pull request May 14, 2024
[Snyk] Fix for 2 vulnerabilities baby636/node#149
Open
@wedataintelligence wedataintelligence mentioned this pull request May 14, 2024
[Snyk] Fix for 2 vulnerabilities wedataintelligence/node#111
Open
@aliceUnhinged613 aliceUnhinged613 mentioned this pull request May 15, 2024
[Snyk] Fix for 1 vulnerabilities aliceUnhinged613/node#129
Open
@kissofire kissofire mentioned this pull request May 20, 2024
[Snyk] Fix for 1 vulnerabilities kissofire/node#130
Open
@aliceUnhinged613 aliceUnhinged613 mentioned this pull request May 21, 2024
[Snyk] Fix for 1 vulnerabilities aliceUnhinged613/node#130
Open
@wedataintelligence wedataintelligence mentioned this pull request May 21, 2024
[Snyk] Fix for 1 vulnerabilities wedataintelligence/node#112
Open
@137717unity 137717unity mentioned this pull request May 21, 2024
[Snyk] Fix for 1 vulnerabilities 137717unity/node#129
Open
@molllyn1 molllyn1 mentioned this pull request May 21, 2024
[Snyk] Fix for 1 vulnerabilities molllyn1/node#113
Open
@ron-a20 ron-a20 mentioned this pull request May 22, 2024
[Snyk] Fix for 1 vulnerabilities ron-a20/node#127
Open
@wedataintelligence wedataintelligence mentioned this pull request Oct 9, 2024
[Snyk] Fix for 3 vulnerabilities wedataintelligence/node#127
Open
@ron-a20 ron-a20 mentioned this pull request Oct 9, 2024
[Snyk] Fix for 3 vulnerabilities ron-a20/node#142
Open
@aliceUnhinged613 aliceUnhinged613 mentioned this pull request Oct 11, 2024
[Snyk] Fix for 4 vulnerabilities aliceUnhinged613/node#146
Open
@137717unity 137717unity mentioned this pull request Oct 13, 2024
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 137717unity/node#145
Open
@kissofire kissofire mentioned this pull request Oct 13, 2024
[Snyk] Security upgrade gatsby from 2.13.73 to 3.13.0 kissofire/node#147
Open
@137717unity 137717unity mentioned this pull request Oct 20, 2024
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 137717unity/node#146
Open
@kissofire kissofire mentioned this pull request Oct 20, 2024
[Snyk] Security upgrade gatsby from 2.13.73 to 3.13.0 kissofire/node#148
Open
@opekeye opekeye mentioned this pull request Oct 20, 2024
[Snyk] Security upgrade gatsby from 2.13.73 to 3.13.0 opekeye/node#17
Open
@molllyn1 molllyn1 mentioned this pull request Oct 22, 2024
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 molllyn1/node#131
Open
@wedataintelligence wedataintelligence mentioned this pull request Oct 22, 2024
[Snyk] Security upgrade gatsby from 2.18.18 to 3.13.0 wedataintelligence/node#129
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BridgeAR BridgeAR BridgeAR left review comments
@mafintosh mafintosh Awaiting requested review from mafintosh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

blocked PRs that are blocked by other issues or PRs. stream Issues and PRs related to Node.js streams.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Duplex stream pipeline regression in 13

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ronag @BridgeAR
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.