Skip to content

readableStream.tee() doesn't work when using process.nextTick(...) #39758

@szmarczak

Description

@szmarczak

Version

v16.6.2

Platform

Linux solus 5.13.8-191.current #1 SMP PREEMPT Fri Aug 6 11:29:58 UTC 2021 x86_64 GNU/Linux

Subsystem

stream/web

What steps will reproduce the bug?

import {ReadableStream} from 'stream/web';

let controller;
let start = c => (controller = c);
let pull = () => {
  if (pull.called) return;
  pull.called = true;

  process.nextTick(() => {
   controller.enqueue(new Uint8Array([102, 111, 111, 98, 97, 114]))

    process.nextTick(() => {
     controller.close()
    });
  });
};

const [a, b] = new ReadableStream({start, pull}).tee();

for (const stream of [a, b]) {
  const chunks = [];

  for await (const chunk of stream) {
    chunks.push(chunk);
  }

  console.log('received:', Buffer.concat(chunks).toString());
}

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

Always.

What is the expected behavior?

received: foobar
received: foobar

What do you see instead?

received: foobar
received:

Additional information

Deno for reference: https://github.com/denoland/deno/blob/a0285e2eb88f6254f6494b0ecd1878db3a3b2a58/ext/web/06_streams.js#L1465-L1543

/cc @ronag @mcollina @jasnell

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