Skip to content

Unable to completely read data from 'bytes' ReadableStream #48233

Closed
@debadree25

Description

@debadree25

Version

20.2.0

Platform

Darwin Debadree-MacBook-Pro.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64

Subsystem

Web streams

What steps will reproduce the bug?

Run the following script in node and in chrome

const toPull = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
const st = new ReadableStream({
  type: 'bytes',
  start(controller) {},

  pull(controller) {
    const chunk = toPull.shift();
    if (chunk === undefined) {
      controller.close();
      return;
    }

    controller.enqueue(new TextEncoder().encode(chunk));
  },
});

const reader = st.getReader({ mode: 'byob' });
const chunks = [];

const decoder = new TextDecoder();

let result;
do {
  result = await reader.read(new Uint8Array(100));
  if (result.value !== undefined)
    chunks.push(decoder.decode(result.value));
} while (!result.done);

console.log(chunks);

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

Always

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

[
  'a', 'b', 'c', 'd',
  'e', 'f', 'g', 'h',
  'i', 'j'
]

The stream should consume all the elements in the toPull array and we must be able to subsequently read this data back, the behaviour is correct in chrome.

What do you see instead?

No output

debadreechatterjee@Debadree-MacBook-Pro node % node test3.mjs
debadreechatterjee@Debadree-MacBook-Pro node % 

Additional information

I tried investigating a little, its possible that there is some hanging promise before the closing of the stream. for example if you logged the values in each step the output would be like this

debadreechatterjee@Debadree-MacBook-Pro node % node test3.mjs
read value a
read value b
read value c
read value d
read value e
read value f
read value g
read value h
read value i
read value j
debadreechatterjee@Debadree-MacBook-Pro node %

note that console to print the chunks array is not printed

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