Skip to content

stream: add auto-destroy mode - #22795

Closed
mafintosh wants to merge 7 commits into
nodejs:masterfrom
mafintosh:auto-destroy-stream
Closed

stream: add auto-destroy mode#22795
mafintosh wants to merge 7 commits into
nodejs:masterfrom
mafintosh:auto-destroy-stream

Conversation

@mafintosh

Copy link
Copy Markdown
Member
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

This adds a new options to the stream constructor called autoDestroy that is default false.
When autoDestroy is enabled .destroy() will automatically be called when the stream has ended and/or finished depending on whether it's a readable/writable/duplex.

This simplifies error handling / resource management for users as you can then always do your teardown logic in the destroy method.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-botnodejs-github-bot added dont-land-on-v6.x http2 Issues or PRs related to the http2 subsystem. stream Issues and PRs related to the stream subsystem. labels Sep 10, 2018
@mcollinamcollina added semver-minor PRs that contain new features and should be released in the next minor version. dont-land-on-v8.x labels Sep 10, 2018
@mcollina

Copy link
Copy Markdown
Member

@mafintosh I think it needs to call .destroy(err) whenever there is a emit('error'), at least in the streams classes and the option is enabled.

I think this is the first step to implement #20096, right?

Comment threaddoc/api/stream.md Outdated

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.

.destroy() -> `.destroy()`?

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.

Can you provide the default value explicitly here?

Comment threaddoc/api/stream.md Outdated

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.

Ditto.

Comment threadlib/_stream_readable.js Outdated

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.

Can't this just be inlined?

@targos

targos commented Sep 10, 2018

Copy link
Copy Markdown
Member

It looks like the code in _stream_readable.js should be in _stream_writable.js and vice versa.

Comment threaddoc/api/stream.md Outdated

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.

Can you provide the default value explicitly here?

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.

Can we maybe check the order of the events/destroy callback as well?

@addaleax

Copy link
Copy Markdown
Member

Gentle ping @mafintosh :)

@targos I think it’s this way around in order to support shutting down Duplex streams?

@mafintosh

Copy link
Copy Markdown
MemberAuthor

@addaleax i'll fix up the nits+comments

@Fishrock123

Copy link
Copy Markdown
Contributor

Seems like a good addition to me, minus others' comments.

@tniessen

Copy link
Copy Markdown
Member

semver-minor commits should contain metadata in the YAML changes section of the affected API.

Comment threadlib/internal/http2/compat.js Outdated

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.

Just to make sure I’m not missing anything – how does this change relate to the others?

@mafintosh
mafintoshforce-pushed the auto-destroy-stream branch 2 times, most recently from bb2cb3c to 387516cCompareOctober 26, 2018 14:08

@mcollinamcollina 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.

LGTM

@mafintosh

Copy link
Copy Markdown
MemberAuthor

Fixed all the nits @addaleax@targos@vsemozhetbyt@Fishrock123

@mafintosh

Copy link
Copy Markdown
MemberAuthor

@mcollinamcollina 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.

LGTM but I would like to see a CITGM run.

Comment threaddoc/api/stream.md Outdated
pr-url: https://github.com/nodejs/node/pull/18438
description: >
Add `emitClose` option to specify if `'close'` is emitted on destroy
- version: TBD

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.

is the value we put here TBD? I never remember.

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.

REPLACEME :)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Ah right! Thanks, will fix

@mafintosh

Copy link
Copy Markdown
MemberAuthor

@mafintosh

Copy link
Copy Markdown
MemberAuthor

@mafintosh

Copy link
Copy Markdown
MemberAuthor

The CITGM runs seem to report similar errors on master + this PR, landing ...

Trott pushed a commit to Trott/io.js that referenced this pull request Oct 30, 2018
PR-URL: nodejs#22795
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@mafintosh

Copy link
Copy Markdown
MemberAuthor

Landed in f24b070

@mafintosh
mafintosh deleted the auto-destroy-stream branch October 30, 2018 14:19
targos pushed a commit that referenced this pull request Nov 2, 2018
PR-URL: #22795
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@watildewatilde mentioned this pull request Nov 6, 2018
3 tasks
@BridgeARBridgeAR mentioned this pull request Nov 14, 2018
BethGriggs pushed a commit that referenced this pull request Apr 8, 2019
PR-URL: #22795
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@BethGriggsBethGriggs mentioned this pull request May 1, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http2Issues or PRs related to the http2 subsystem.semver-minorPRs that contain new features and should be released in the next minor version.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@mafintosh@nodejs-github-bot@mcollina@targos@addaleax@Fishrock123@tniessen@mscdex@jasnell@vsemozhetbyt