Skip to content

Stream async iteration breaks with derived streams #28141

Description

@gordonmleigh
  • 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.

Activity

  1. gordonmleigh commented on Jun 9, 2019

    @gordonmleigh
    Author

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

  2. added
    streamIssues and PRs related to Node.js streams.
    on Jun 9, 2019
  3. addaleax commented on Jun 9, 2019

    @addaleax
    Member

    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.

  4. lpinca commented on Jun 9, 2019

    @lpinca
    Member

    destroy() callback is indeed "private"

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

    _destroy() callback is not.

  5. jasnell commented on Jun 26, 2020

    @jasnell
    Member

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

  6. ronag commented on Jun 28, 2020

    @ronag
    Member

    Was fixed in #29176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions