Skip to content

stream: avoid pause with unpipe in buffered write - #2325

Closed
mscdex wants to merge 1 commit into
nodejs:masterfrom
mscdex:fix-stream-regression
Closed

stream: avoid pause with unpipe in buffered write#2325
mscdex wants to merge 1 commit into
nodejs:masterfrom
mscdex:fix-stream-regression

Conversation

@mscdex

Copy link
Copy Markdown
Contributor

If a pipe is cleaned up (due to unpipe) during a failed write(),
the source stream can get stuck in a paused state.

Fixes: #2323

@mscdexmscdex added the stream Issues and PRs related to the stream subsystem. label Aug 7, 2015
@LinusU

Copy link
Copy Markdown
Contributor

@mscdex This fixes the problem, thank you so much, would love to see this landed 💯 👍

I'm currently using this as a workaround. Is it stupid as fuck or should it work?

functiondone(err){if(isDone)returnisDone=truereq.unpipe(busboy)req.resume()busboy.removeAllListeners()/* Work around bug in Node.js * https://github.com/nodejs/node/issues/2323 */setImmediate(function(){if(req._readableState.awaitDrain===1){req._readableState.awaitDrain--req.resume()}})onFinished(req,function(){next(err)})}

I'm also having some trouble which forces me to add the onFinished part, it seems like I have to wait for all data to arrive before I can send data back... I'll try to investigate and open another issue.

Again, thank you for the quick help!

@mscdex

Copy link
Copy Markdown
ContributorAuthor

/cc @nodejs/streams

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the significants of this number, is it being used to bust the buffer?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was copied from the test case in #2323. I think the point though is to fill up the internal buffer to cause the write() to return false.

@LinusU

Copy link
Copy Markdown
Contributor

If someone could help me to find a workaround for earlier Node versions (preferably back to 0.10) that would be very much appreciated.

I've tried here: expressjs/multer#205

@mscdex

Copy link
Copy Markdown
ContributorAuthor

Ok, updated PR according to suggestions.

@Fishrock123

Copy link
Copy Markdown
Contributor

@mscdex
mscdexforce-pushed the fix-stream-regression branch 2 times, most recently from 9b13ecb to b879ce0CompareOctober 11, 2015 16:03
@mscdex

Copy link
Copy Markdown
ContributorAuthor

updated to use common.mustCall() in the test.

CI: https://ci.nodejs.org/job/node-test-commit/799/
Looks like two of the Windows machines failed for different reasons. Not sure what's up with that.

Does this look good to land now?

@thefourtheye

Copy link
Copy Markdown
Contributor

There can be a comment which explains the importance of 56000 or link to this PR. LGTM.

@mscdex
mscdexforce-pushed the fix-stream-regression branch from b879ce0 to 6176c8bCompareOctober 11, 2015 16:56
If a pipe is cleaned up (due to unpipe) during a write that
returned false, the source stream can get stuck in a paused state.
Fixes: nodejs#2323
@mscdex
mscdexforce-pushed the fix-stream-regression branch from 6176c8b to 91819e0CompareOctober 11, 2015 18:06
mscdex added a commit that referenced this pull request Oct 11, 2015
If a pipe is cleaned up (due to unpipe) during a write that
returned false, the source stream can get stuck in a paused state.
Fixes: #2323
PR-URL: #2325
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@mscdex

Copy link
Copy Markdown
ContributorAuthor

Landed in 6899094.

@mscdexmscdex closed this Oct 11, 2015
Trott pushed a commit to Trott/io.js that referenced this pull request Oct 12, 2015
If a pipe is cleaned up (due to unpipe) during a write that
returned false, the source stream can get stuck in a paused state.
Fixes: nodejs#2323
PR-URL: nodejs#2325
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@LinusU

Copy link
Copy Markdown
Contributor

Nice, thanks!

mscdex added a commit that referenced this pull request Oct 12, 2015
If a pipe is cleaned up (due to unpipe) during a write that
returned false, the source stream can get stuck in a paused state.
Fixes: #2323
PR-URL: #2325
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@jasnell

Copy link
Copy Markdown
Member

Landed in v4.x in 7b9f78a

@omrilitov

Copy link
Copy Markdown

Is this fixed in v4.2.0?
It's listed on the commits but it got merged after 4.2.0 release

@mscdexmscdex changed the title stream: avoid pause with unpipe in failed writestream: avoid pause with unpipe in buffered writeOct 26, 2015
@mscdex

Copy link
Copy Markdown
ContributorAuthor

@omrilitov It's included in v4.2.0.

@mscdex
mscdex deleted the fix-stream-regression branch December 17, 2015 18:20
addaleax added a commit to addaleax/node that referenced this pull request Apr 3, 2016
In 6899094 (nodejs#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: nodejs#5820
jasnell pushed a commit that referenced this pull request Apr 12, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 19, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 20, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 20, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit that referenced this pull request Apr 26, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 30, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 6, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 18, 2016
In 6899094 (#2325),
the conditions for increasing `readableState.awaitDrain` when
writing to a piping destination returns false were changed so
that they could not actually be met, effectively leaving
`readableState.awaitDrain` with a constant value of 0.
This patch changes the conditions to testing whether the
stream for which `.write()` returned false is still a piping
destination, which was likely the intention of the original
patch.
Fixes: #5820Fixes: #5257
PR-URL: #6023
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@mscdex@LinusU@Fishrock123@thefourtheye@jasnell@omrilitov@chrisdickinson@calvinmetcalf@MylesBorins