Sitelet https://web.archive.org/web/20220323011150/https://github.com/nodejs/node/pull/35348
Skip to content
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: writableNeedDrain #35348

Closed
wants to merge 5 commits into from
Closed

Conversation

ronag
Copy link
Member

@ronag ronag commented Sep 25, 2020 •

Don't write to a stream which already has a full buffer.

Fixes: #35341

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

@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Sep 25, 2020

Review requested:

@nodejs-github-bot nodejs-github-bot added the lib / src label Sep 25, 2020
@ronag
Copy link
Member Author

@ronag ronag commented Sep 25, 2020

Needs tests.

@ronag ronag force-pushed the stream-writable-need-drain branch from 8d1c665 to deabf75 Compare Sep 25, 2020
@ronag ronag force-pushed the stream-writable-need-drain branch from deabf75 to 3976f6a Compare Sep 25, 2020
Don't write to a stream which already has a full buffer.

Fixes: nodejs#35341
@ronag ronag force-pushed the stream-writable-need-drain branch from 3976f6a to 591616f Compare Sep 25, 2020
ronag added a commit to nodejs/undici that referenced this issue Sep 25, 2020
ronag added a commit to nodejs/undici that referenced this issue Sep 25, 2020
ronag added a commit to nodejs/undici that referenced this issue Sep 25, 2020
ronag added a commit to nodejs/undici that referenced this issue Sep 25, 2020
Copy link
Member

@mcollina mcollina left a comment

lgtm

doc/api/stream.md Outdated Show resolved Hide resolved
lib/internal/streams/readable.js Outdated Show resolved Hide resolved
@ronag ronag force-pushed the stream-writable-need-drain branch from 386afdf to 0811886 Compare Oct 9, 2020
@ronag ronag marked this pull request as ready for review Oct 10, 2020
@ronag
Copy link
Member Author

@ronag ronag commented Oct 10, 2020

@ronag ronag requested review from mcollina, addaleax and lpinca Oct 10, 2020
@ronag ronag added the request-ci label Oct 10, 2020
@github-actions github-actions bot removed the request-ci label Oct 10, 2020
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Oct 10, 2020

if (dest.writableNeedDrain === true) {
if (state.flowing) {
src.pause();
}
Copy link
Member Author

@ronag ronag Oct 10, 2020

Choose a reason for hiding this comment

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

I'm a little unsure how this affects the case where src is already piped to other destinations?

Copy link
Member

@lundibundi lundibundi Oct 12, 2020

Choose a reason for hiding this comment

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

🤔 what about adding the stream to the state.awaitDrainWriters (refs pipeOnDrain + ondata(chunk)). Though that may require copying https://github.com/nodejs/node/pull/35348/files#diff-0117344ddd481d021ad96b9c8eea78a5R741-R747 from ondata...

Copy link
Member Author

@ronag ronag Oct 12, 2020 •

Choose a reason for hiding this comment

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

I have no idea how that works or what it is intended for.

Copy link
Member

@lundibundi lundibundi Oct 12, 2020

Choose a reason for hiding this comment

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

Well, same 😄, based on the initial look it is a list of writables to wait for a drain event so this case seems fitting.
Let's ping @addaleax @BridgeAR @mscdex as most "recent" collaborators according to git-blame.

Copy link

@HomerSp HomerSp Dec 18, 2020

Choose a reason for hiding this comment

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

Any chance this can be reverted or done some other way? It seems to cause issues with the source getting stuck in a paused state if you previously fed the output buffer with a lot of data, see eg, electron/asar#210 That module basically just appends a bunch of files to a single binary, but after a random amount of files it gets stuck due to the source being in a paused state.
This could, of course, be easily worked around by adding the writableNeedDrain loop as in the issue above, or adding a resume call to the stream, but I feel like that shouldn't really be necessary.

@github-actions github-actions bot removed the request-ci label Oct 12, 2020
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Oct 12, 2020

@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Oct 12, 2020

@@ -801,7 +801,12 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
dest.emit('pipe', src);

// Start the flow if it hasn't been started already.
if (!state.flowing) {

if (dest.writableNeedDrain === true) {
Copy link
Member

@lundibundi lundibundi Oct 12, 2020

Choose a reason for hiding this comment

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

Nit: why not:

Suggested change
if (dest.writableNeedDrain === true) {
if (dest.writableNeedDrain) {

if (dest.writableNeedDrain === true) {
if (state.flowing) {
src.pause();
}
Copy link
Member

@lundibundi lundibundi Oct 12, 2020

Choose a reason for hiding this comment

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

🤔 what about adding the stream to the state.awaitDrainWriters (refs pipeOnDrain + ondata(chunk)). Though that may require copying https://github.com/nodejs/node/pull/35348/files#diff-0117344ddd481d021ad96b9c8eea78a5R741-R747 from ondata...

ronag added a commit to nodejs/undici that referenced this issue Nov 2, 2020
@aduh95 aduh95 added the author ready label Nov 8, 2020
@aduh95
Copy link
Contributor

@aduh95 aduh95 commented Nov 9, 2020

@ronag is this ready to land?

Copy link
Member

@mcollina mcollina left a comment

lgtm

@aduh95
Copy link
Contributor

@aduh95 aduh95 commented Nov 10, 2020

Landed in dd0f8f1

@aduh95 aduh95 closed this Nov 10, 2020
aduh95 added a commit that referenced this issue Nov 10, 2020
Don't write to a stream which already has a full buffer.

Fixes: #35341

PR-URL: #35348
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
danielleadams added a commit that referenced this issue Nov 10, 2020
Don't write to a stream which already has a full buffer.

Fixes: #35341

PR-URL: #35348
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@danielleadams danielleadams mentioned this pull request Nov 10, 2020
ronag added a commit to nodejs/undici that referenced this issue Nov 12, 2020
ronag added a commit to nodejs/undici that referenced this issue Nov 12, 2020
ronag added a commit to nodejs/undici that referenced this issue Nov 13, 2020
BethGriggs added a commit that referenced this issue Dec 9, 2020
Don't write to a stream which already has a full buffer.

Fixes: #35341

PR-URL: #35348
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@BethGriggs BethGriggs added the semver-minor label Dec 10, 2020
@ronag ronag added dont-land-on-v10.x dont-land-on-v12.x dont-land-on-v14.x labels Dec 18, 2020
@ronag
Copy link
Member Author

@ronag ronag commented Dec 18, 2020

Adding don't land labels until #36544 is resolved.

@ronag ronag removed the dont-land-on-v14.x label Dec 20, 2020
@ronag
Copy link
Member Author

@ronag ronag commented Dec 20, 2020

This requires bug fix in #36563

targos added a commit that referenced this issue May 1, 2021
Don't write to a stream which already has a full buffer.

Fixes: #35341

PR-URL: #35348
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@danielleadams danielleadams mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready dont-land-on-v12.x semver-minor stream
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

10 participants