Skip to content

ReadableStream.values().return() throws ERR_INTERNAL_ASSERTION with two next(), one resolved, one pending #57679

Open
@compulim

Description

@compulim

Version

22.14.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

internal/webstreams/readablestream

What steps will reproduce the bug?

(async () => {
  let controller;
  const stream = new ReadableStream({
    start(c) {
      controller = c;
    }
  });

  const values = stream.values();

  let next1Promise = values.next();
  let next2Promise = values.next(); // Must have second next() pending and unresolved to repro

  controller.enqueue(1); // enqueue() will resolve first next() but leaving second next() pending

  await next1Promise; // Must wait for first next() to resolve to repro

  values.return(); // Will throw ERR_INTERNAL_ASSERTION
})();

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

Two next() is called with one resolved and another one pending. Then call return() would throw.

What is the expected behavior? Why is that the expected behavior?

return() should not error out. It should not resolve until the second next() is resolved.

Please refer to https://streams.spec.whatwg.org/#rs-asynciterator related to how functions are resolved.

What do you see instead?

> Uncaught:
Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at assert (node:internal/assert:14:11)
    at returnSteps (node:internal/webstreams/readablestream:510:7)
    at Object.return (node:internal/webstreams/readablestream:557:11) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Additional information

The same code also cause STATUS_ACCESS_VIOLATION in Chrome 134.0.6998.89, and Edge 134.0.3124.93. And NS_ERROR_FAILURE in Firefox 136.0.4.

Node.js CLI 22.14.0

Image

Chrome 134.0.6998.89

Image

Edge 134.0.3124.93

Image

Firefox 136.0.4

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions