oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.5k stars 2.79k forks source link

TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController #12908

Open brettwillis opened 4 months ago

brettwillis commented 4 months ago

What version of Bun is running?

1.1.21+70ca2b76c

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Send request with body to the Bun server, request.body.getReader() throws when trying to obtain a ReadableStreamBYOBReader.

// (simplified)
Bun.serve({
  async fetch(req) {
    const reader = await req.body.getReader({ mode: 'byob' }); // <-- TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController
    // ...
  }
})

What is the expected behavior?

ReadableStream should support byob mode.

What do you see instead?

TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController

Additional information

No response

brettwillis commented 1 month ago

Hey guys it's been a while and no triage. Are "byob" streams intentionally not implemented?

// test.js
Bun.serve({
  host: 'localhost',
  port: '8080',
  async fetch(req) {
    const reader = await req.body?.getReader({ mode: 'byob' });
    return new Response('done');
  }
});

Then curl http://localhost:8080 -d 'Hello'.

1 | Bun.serve({
2 |   host: 'localhost',
3 |   port: '8080',
4 |   async fetch(req) {
5 |     const reader = await req.body?.getReader({ mode: 'byob' });
              ^
TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController
      at /Users/..../test.js:5:36
      at fetch (/Users/..../test.js:4:15)
POST - / failed
brettwillis commented 1 month ago

Docs claim that ReadableStream is fully implemented https://bun.sh/docs/runtime/nodejs-apis#readablestream. Am I the only one encountering this?

paperdave commented 1 week ago

i just hit this in the safari browser while working on #15181, which is funny that the top google search for that message is an issue in bun. the bug seems to be something in BYOB streams, since the code sample i had (using streaming fetch in the browser) worked in chrome/v8. adding the jsc tag here.

RealmyTheMan commented 6 days ago

Docs claim that ReadableStream is fully implemented https://bun.sh/docs/runtime/nodejs-apis#readablestream. Am I the only one encountering this?

I'm not using them directly, but rather through the fileTypeFromStream method on the file-type package. Regardless, I'm also using Bun, and I believe I have the same problem.