oven-sh / bun

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

Upload large files http server bug #13804

Open SupertigerDev opened 2 months ago

SupertigerDev commented 2 months ago

What version of Bun is running?

1.1.26

What platform is your computer?

Windows 11 64bit 23H2 (uname command is not found for some reason)

What steps can reproduce the bug?

Upload a large binary(5gb) using postman

const server = Bun.serve({
  reusePort: true,
  port: 8080,

  maxRequestBodySize: 1024 * 1024 * 10000, // 10GB
  async fetch(req) {
    const reader = req.body?.getReader();
    await reader?.read();

    return new Response("Done!");
  },
});

console.log(`Listening on ${server.url}`);

image

What is the expected behavior?

It should not crash. Just like nodejs, it shoud load it in small chunks.

What do you see instead?

image

Additional information

While this code above crashes, the code below loads EVERYTHING in memory which is not ideal. It should load it in chunks, just like nodejs.

const server = Bun.serve({
  reusePort: true,
  port: 8080,

  maxRequestBodySize: 1024 * 1024 * 10000, // 10GB
  async fetch(req) {
    const formData = await req.formData();

    return new Response("Done!");
  },
});

console.log(`Listening on ${server.url}`);

image

Jarred-Sumner commented 2 months ago

ah yeah, this is an easily fixable problem

though we shouldn't be pre-allocating more than 4 GB at a time anyway

SupertigerDev commented 2 months ago

Thanks for your reply! Although I'm confused with it 😅 was there an issue with my approach of the code?