★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/22795Nouvelle recherche | Portail wanayoo
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: add auto-destroy mode #22795

Closed
wants to merge 7 commits into from
Closed

Conversation

mafintosh
Copy link
Member

@mafintosh mafintosh commented Sep 10, 2018

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.

@mcollina
Copy link
Member

@mcollina mcollina commented Sep 10, 2018

@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?

@@ -1492,6 +1492,8 @@ changes:
[`stream._destroy()`][writable-_destroy] method.
* `final` {Function} Implementation for the
[`stream._final()`][stream-_final] method.
* `autoDestroy` {boolean} Whether this stream should automatically call
.destroy() on itself after ending.
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Sep 10, 2018

Choose a reason for hiding this comment

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

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

Copy link
Member

@addaleax addaleax Sep 11, 2018

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?

@@ -1741,6 +1743,8 @@ constructor and implement the `readable._read()` method.
method.
* `destroy` {Function} Implementation for the
[`stream._destroy()`][readable-_destroy] method.
* `autoDestroy` {boolean} Whether this stream should automatically call
.destroy() on itself after ending.
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Sep 10, 2018

Choose a reason for hiding this comment

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

Ditto.

@@ -1075,6 +1078,10 @@ function endReadable(stream) {
}
}

function writableAutoDestroy(wState) {
return !wState || (wState.autoDestroy && wState.finished);
Copy link
Contributor

@mscdex mscdex Sep 10, 2018

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

@targos targos commented Sep 10, 2018

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

@@ -1492,6 +1492,8 @@ changes:
[`stream._destroy()`][writable-_destroy] method.
* `final` {Function} Implementation for the
[`stream._final()`][stream-_final] method.
* `autoDestroy` {boolean} Whether this stream should automatically call
.destroy() on itself after ending.
Copy link
Member

@addaleax addaleax Sep 11, 2018

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?

t.resume();
t.on('end', common.mustCall());
t.on('finish', common.mustCall());
t.on('close', common.mustCall());
Copy link
Member

@addaleax addaleax Sep 11, 2018

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
Member

@addaleax addaleax commented Sep 14, 2018

Gentle ping @mafintosh :)

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

@mafintosh
Copy link
Member Author

@mafintosh mafintosh commented Sep 17, 2018

@addaleax i'll fix up the nits+comments

@Fishrock123
Copy link
Member

@Fishrock123 Fishrock123 commented Sep 17, 2018

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

@tniessen
Copy link
Member

@tniessen tniessen commented Sep 19, 2018

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

@@ -251,6 +251,7 @@ function onStreamTimeout(kind) {

class Http2ServerRequest extends Readable {
constructor(stream, headers, options, rawHeaders) {
if (!options) options = {};
Copy link
Member

@addaleax addaleax Sep 22, 2018

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 mafintosh force-pushed the auto-destroy-stream branch 2 times, most recently from bb2cb3c to 387516c Oct 26, 2018
@mafintosh mafintosh force-pushed the auto-destroy-stream branch from 387516c to ccc94a9 Oct 26, 2018
Copy link
Member

@mcollina mcollina left a comment

LGTM

@mafintosh
Copy link
Member Author

@mafintosh mafintosh commented Oct 29, 2018

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

@mafintosh
Copy link
Member Author

@mafintosh mafintosh commented Oct 29, 2018

Copy link
Member

@mcollina mcollina left a comment

LGTM but I would like to see a CITGM run.

@@ -1493,6 +1493,11 @@ changes:
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
Member

@mcollina mcollina Oct 29, 2018

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
Member

@addaleax addaleax Oct 29, 2018

Choose a reason for hiding this comment

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

REPLACEME :)

Copy link
Member Author

@mafintosh mafintosh Oct 29, 2018

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
Member Author

@mafintosh mafintosh commented Oct 30, 2018

@mafintosh
Copy link
Member Author

@mafintosh mafintosh commented Oct 30, 2018

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

Trott pushed a commit to Trott/io.js that referenced this issue 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
Member Author

@mafintosh mafintosh commented Oct 30, 2018

Landed in f24b070

@mafintosh mafintosh closed this Oct 30, 2018
@mafintosh mafintosh deleted the auto-destroy-stream branch Oct 30, 2018
targos added a commit that referenced this issue 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>
BethGriggs pushed a commit that referenced this issue 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>
@BethGriggs BethGriggs mentioned this pull request May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants