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.Readable.from does not always close synchronous generators #32842

Closed
vadzim opened this issue Apr 14, 2020 · 0 comments
Closed

stream.Readable.from does not always close synchronous generators #32842

vadzim opened this issue Apr 14, 2020 · 0 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@vadzim
Copy link
Contributor

vadzim commented Apr 14, 2020

  • Version: 12.16.2, 13.12.0
  • Platform: linux
  • Subsystem: arch

What steps will reproduce the bug?

If synchronous generator wrapped with stream.Readable.from emits rejected Promise then finally blocks of that generator is never called.
But if that generator is consumed with general for-of loop then finally blocks are called as expected.

stream.Readable.from(function*() {
  try {
    yield Promise.resolve(1)
    yield Promise.reject('error')
  } finally {
    console.log('fin')
  }
}())
.on('data',x=>console.log(x))
.on('error',e=>console.log(e))

It logs

1
error

but does not log fin.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

stream.Readable.from should either not resolve Promises yielded from synchronous generators and should pass unresolved Promises to the returned stream or should properly close generator even if it yields rejected Promise.

Additional information

To fix this there should be called iterator.return if await value throws.

readable.destroy(err);

@himself65 himself65 added the stream Issues and PRs related to the stream subsystem. label Apr 14, 2020
vadzim added a commit to vadzim/node that referenced this issue Apr 14, 2020
Use for-of loop to traverse iterator and properly close it
if not all of its values are consumed.

Fixes: nodejs#32842
vadzim added a commit to vadzim/node that referenced this issue Apr 15, 2020
Call iterator.return() if not all of its values are consumed.

Fixes: nodejs#32842
@ronag ronag closed this as completed in 8a3fa32 Apr 18, 2020
BethGriggs pushed a commit that referenced this issue Apr 27, 2020
Call iterator.return() if not all of its values are consumed.

Fixes: #32842

PR-URL: #32844
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
BridgeAR pushed a commit that referenced this issue Apr 28, 2020
Call iterator.return() if not all of its values are consumed.

Fixes: #32842

PR-URL: #32844
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
targos pushed a commit that referenced this issue May 7, 2020
Call iterator.return() if not all of its values are consumed.

Fixes: #32842

PR-URL: #32844
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
targos pushed a commit that referenced this issue May 13, 2020
Call iterator.return() if not all of its values are consumed.

Fixes: #32842

PR-URL: #32844
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants