Skip to content

Conversation

@ronag
Copy link
Member

@ronagronag commented Aug 6, 2019

Clarifies that creating multiple async iterators from the same stream can lead to event listener leak.

Checklist

@nodejs-github-botnodejs-github-bot added doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem. labels Aug 6, 2019
@ronagronagforce-pushed the doc-async-iterator branch 4 times, most recently from 8a6b51d to 5fb5109CompareAugust 6, 2019 09:47
This was referenced Aug 6, 2019
@ronag
Copy link
MemberAuthor

ronag commented Aug 6, 2019

@Trott flaky V8 compile, please restart?

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
streams using async iterators any errors emitted after `'end'` or `'close'`
streams using async iterators, any errors emitted after `'end'` or `'close'`

Trott
Trott previously approved these changes Aug 7, 2019
@Trott
Copy link
Member

Trott commented Aug 7, 2019

@nodejs/streams

@TrottTrott dismissed their stale reviewAugust 7, 2019 05:03

going to defer to stream folks on this

Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

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

I don't think we should land this change.

When a stream is async iterated it will always exit the iteration in a destroyed state, i.e. break or throw will call destroy() on the stream. As a result, we cannot create multiple streams one after the other.
Moreover, creating multiple parallel AsyncIterators out of the same stream is problematic and should not be done: the behavior is going to be very unpredictable (which of the two iterators will get the data? only one will).

What should be documented is that, because it's left in a destroyed state, there will be a 'error' event handler attached to prevent further exceptions to crash the process.

@ronag
Copy link
MemberAuthor

ronag commented Aug 7, 2019

Isn’t it possible to create multiple iterators? i.e when using the iterator API directly and not through a for loop?

Should we maybe throw if a second iterative is created?

@mcollina
Copy link
Member

Isn’t it possible to create multiple iterators? i.e when using the iterator API directly and not through a for loop?

The semantics of that are currently not what somebody is going to expect. The two iterators are going to compete for the chunks (as they use 'readable' / read() internally). An iterator does not use .pipe(), so there is no multiple destination logic in there.

@ronag
Copy link
MemberAuthor

ronag commented Aug 7, 2019

The semantics of that are currently not what somebody is going to expect. The two iterators are going to compete for the chunks (as they use 'readable' / read() internally). An iterator does not use .pipe(), so there is no multiple destination logic in there.

Hence, should we throw if a secondary iterator is created? Also possibly add a note in the docs?

@ronagronagforce-pushed the doc-async-iterator branch from 5fb5109 to 952d08aCompareAugust 7, 2019 14:24
@ronag
Copy link
MemberAuthor

ronag commented Aug 7, 2019

Updated description in accordance with @mcollina's previous suggestion.

@jasnell
Copy link
Member

Throwing if there's an attempt to create a second iterator would make sense to me. What do you think @mcollina?

Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina
Copy link
Member

Throwing if there's an attempt to create a second iterator would make sense to me. What do you think @mcollina?

I'm definitely +1 on that. @ronag, would you like to send a PR for that?

@ronagronag mentioned this pull request Aug 9, 2019
4 tasks
@ronagronagforce-pushed the doc-async-iterator branch from 952d08a to e4de3f0CompareAugust 9, 2019 16:03
@ronag
Copy link
MemberAuthor

ronag commented Aug 12, 2019

@Trott: This fails because I didn't rebase master. However, since it's a simple doc change I don't think it's worth a rebase?

@Trott
Copy link
Member

```

Async iterators register a permanent error handler on the stream to prevent any
unhandled post-destroy errors.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure that what I"m about to suggest is a good idea, so I'll defer to everyone else's judgment:

Is it worth re-wording to make it clear that this means the destroy() method?

Suggested change
unhandled post-destroy errors.
unhandled errors after `destroy()` executes.

I'm not sure that's an improvement to be honest, but maybe?

@Trott
Copy link
Member

Landed in d7a4ace

@TrottTrott closed this Aug 12, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Aug 12, 2019
Clarifies that creating multiple async iterators from the same stream can lead to event listener leak. PR-URL: nodejs#28997 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
targos pushed a commit that referenced this pull request Aug 19, 2019
Clarifies that creating multiple async iterators from the same stream can lead to event listener leak. PR-URL: #28997 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
@targostargos mentioned this pull request Aug 19, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docIssues and PRs related to the documentations.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@ronag@nodejs-github-bot@Trott@mcollina@jasnell@trivikr