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 async iteration breaks with derived streams #28141

Closed
gordonmleigh opened this issue Jun 9, 2019 · 5 comments
Closed

Stream async iteration breaks with derived streams #28141

gordonmleigh opened this issue Jun 9, 2019 · 5 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@gordonmleigh
Copy link

  • Version: v12.4.0
  • Platform: Darwin hostname.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • Subsystem: Stream

The async iterator functionality relies on a private API on destroy that accepts a second argument which is a callback. See here:

  return() {
    // destroy(err, cb) is a private API.
    // We can guarantee we have that here, because we control the
    // Readable class this is attached to.
    return new Promise((resolve, reject) => {
      this[kStream].destroy(null, (err) => {
        if (err) {
          reject(err);
          return;
        }
        resolve(createIterResult(undefined, true));
      });
    });
  }

This private API is not present on objects derived from Readable that have _destroy overridden. This means that premature exit from a for await loop which triggers the above return method will cause the program to end after running out of async continuations, as the callback is never called.

@gordonmleigh
Copy link
Author

My bad, the documentation appears to indicate that the _destroy method should support a callback. Why is the callback API private anyway?

@addaleax addaleax added the stream Issues and PRs related to the stream subsystem. label Jun 9, 2019
@addaleax
Copy link
Member

addaleax commented Jun 9, 2019

I’m confused. destroy() is certainly not a private API – it’s documented as public API, and so the comment in our source code seems like a lie.

_destroy() is private in the sense that it should be overridden by subclasses, and only called from the streams code.

@lpinca
Copy link
Member

lpinca commented Jun 9, 2019

destroy() callback is indeed "private"

// Undocumented cb() API, needed for core, not for public API

_destroy() callback is not.

@jasnell
Copy link
Member

jasnell commented Jun 26, 2020

@nodejs/stream ... is there anything actionable here?

@ronag
Copy link
Member

ronag commented Jun 28, 2020

Was fixed in #29176

@ronag ronag closed this as completed Jun 28, 2020
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

No branches or pull requests

5 participants