FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stream: use state.ending to see if stream called end() by MoonBall · Pull Request #18170 · nodejs/node · GitHub

/ node Public

stream: use state.ending to see if stream called end() - #18170

Closed
MoonBall wants to merge 1 commit into
nodejs:masterfrom
MoonBall:use-state.ending-to-trigger-writeAfterEnd
Closed

stream: use state.ending to see if stream called end()#18170
MoonBall wants to merge 1 commit into
nodejs:masterfrom
MoonBall:use-state.ending-to-trigger-writeAfterEnd

Conversation

MoonBall commented Jan 16, 2018
edited by mcollina
Loading

Copy link
Copy Markdown
Member

Calling writable.end() will probably synchronously call
writable.write(), in such a situation the state.ended
is false and writable.write() doesn't trigger writeAfterEnd().

There is an example as below:

const { Writable } = require('stream');

let data = '';
const w = new Writable({
  write: function(chunk, encoding, cb) {
    process.nextTick(() => {
      data += chunk;
      cb();
    });
  },
});

w.on('prefinish', () => {
  // w.write('prefinish');
});
w.on('finish', () => {
  w.write('finish');
});

w.end(() => {
  console.log(data);
});

when 'prefinish' listener doesn't call w.write(), w.end() will synchronously emit 'finish' event. The console's output is: finish.
when 'prefinish' listener calls w.write(), the 'finish' event will be asynchronously emitted. The w.write() that called by the 'finish' listener will trigger writeAfterEnd() and throw a Error.

I think using state.ended to decide whether to trigger writeAfterEnd is diffcult to understand and is somewhat unreasonable.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

stream

nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label Jan 16, 2018
apapirovski requested a review from mcollina January 16, 2018 16:37

Copy link
Copy Markdown
Member

I do not understand what is the current behavior and what you want to achieve with this change. Can you please edit the description of this PR to clarify that? Examples works better than a textual form.

Can you please add/change the unit tests?

Copy link
Copy Markdown
Member Author

@mcollina I added test cases. are they right?

Copy link
Copy Markdown
Member

mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 17, 2018

Copy link
Copy Markdown
Member

This is how i would expect things to work today and I would consider this a bug

mcollina removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 17, 2018

Copy link
Copy Markdown
Member Author

@mcollina There are some failed checks. What should I do?

Copy link
Copy Markdown
Member

I think it's CI that is flaky.

CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1208/

addaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would feel okay with considering this semver-major just to be careful (but also okay with not doing so).

Copy link
Copy Markdown
Member

We can land it semver-minor and taking it some more time before backporting.

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

Can you please rebase on top of master?

Calling `writable.end()` will probably synchronously call
`writable.write()`, in such a situation the `state.ended`
is false and `writable.write()` doesn't trigger `writeAfterEnd()`.
MoonBall force-pushed the use-state.ending-to-trigger-writeAfterEnd branch from 1401476 to e6d3654 Compare January 18, 2018 17:59

Copy link
Copy Markdown
Member Author

Rebased.

Copy link
Copy Markdown
Member

mcollina added semver-minor PRs that contain new features and should be released in the next minor version. baking-for-lts PRs that need to wait before landing in a LTS release. dont-land-on-v4.x labels Jan 19, 2018

Copy link
Copy Markdown
Member

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Copy link
Copy Markdown
Member

CITGM seems similar, landing.

Copy link
Copy Markdown
Member

Landed as c7ca07a

mcollina closed this Jan 30, 2018
mcollina pushed a commit that referenced this pull request Jan 30, 2018
Calling `writable.end()` will probably synchronously call
`writable.write()`, in such a situation the `state.ended`
is false and `writable.write()` doesn't trigger `writeAfterEnd()`.

PR-URL: #18170
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request Jan 30, 2018
Calling `writable.end()` will probably synchronously call
`writable.write()`, in such a situation the `state.ended`
is false and `writable.write()` doesn't trigger `writeAfterEnd()`.

PR-URL: #18170
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas added a commit that referenced this pull request Jan 30, 2018
Notable changes:

* cluster
  - add cwd to cluster.settings (cjihrig) [#18399](#18399)
* deps
  - upgrade libuv to 1.19.1 (cjihrig) [#18260](#18260)
* meta
  - add Leko to collaborators (Leko) [#18117](#18117)
  - add vdeturckheim as collaborator (vdeturckheim) [#18432](#18432)
* n-api
  - expose n-api version in process.versions (Michael Dawson) [#18067](#18067)
* perf_hooks
  - add performance.clear() (James M Snell) [#18046](#18046)
* stream
  - avoid writeAfterEnd() while ending (陈刚) [#18170](#18170)

PR-URL: #18464
evanlucas added a commit that referenced this pull request Jan 31, 2018
Notable changes:

* cluster
  - add cwd to cluster.settings (cjihrig) [#18399](#18399)
* deps
  - upgrade libuv to 1.19.1 (cjihrig) [#18260](#18260)
* meta
  - add Leko to collaborators (Leko) [#18117](#18117)
  - add vdeturckheim as collaborator (vdeturckheim) [#18432](#18432)
* n-api
  - expose n-api version in process.versions (Michael Dawson) [#18067](#18067)
* perf_hooks
  - add performance.clear() (James M Snell) [#18046](#18046)
* stream
  - avoid writeAfterEnd() while ending (陈刚) [#18170](#18170)

PR-URL: #18464
evanlucas added a commit that referenced this pull request Feb 1, 2018
Notable changes:

* cluster
  - add cwd to cluster.settings (cjihrig) [#18399](#18399)
* deps
  - upgrade libuv to 1.19.1 (cjihrig) [#18260](#18260)
* meta
  - add Leko to collaborators (Leko) [#18117](#18117)
  - add vdeturckheim as collaborator (vdeturckheim) [#18432](#18432)
* n-api
  - expose n-api version in process.versions (Michael Dawson) [#18067](#18067)
* perf_hooks
  - add performance.clear() (James M Snell) [#18046](#18046)
* stream
  - avoid writeAfterEnd() while ending (陈刚) [#18170](#18170)

PR-URL: #18464
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Calling `writable.end()` will probably synchronously call
`writable.write()`, in such a situation the `state.ended`
is false and `writable.write()` doesn't trigger `writeAfterEnd()`.

PR-URL: nodejs#18170
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Notable changes:

* cluster
  - add cwd to cluster.settings (cjihrig) [nodejs#18399](nodejs#18399)
* deps
  - upgrade libuv to 1.19.1 (cjihrig) [nodejs#18260](nodejs#18260)
* meta
  - add Leko to collaborators (Leko) [nodejs#18117](nodejs#18117)
  - add vdeturckheim as collaborator (vdeturckheim) [nodejs#18432](nodejs#18432)
* n-api
  - expose n-api version in process.versions (Michael Dawson) [nodejs#18067](nodejs#18067)
* perf_hooks
  - add performance.clear() (James M Snell) [nodejs#18046](nodejs#18046)
* stream
  - avoid writeAfterEnd() while ending (陈刚) [nodejs#18170](nodejs#18170)

PR-URL: nodejs#18464
MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minor PRs that contain new features and should be released in the next minor version. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL