Open niklas-stegmann opened 1 week ago
This happens due to the use of sleep
(or any long-running async task). We are reading data from the socket so that the next request can be processed and so that the developer is able to read the request body after an async task has completed.
We could tweak the behavior here though and make it only start reading in the data once the getReader() or equivalent function has been called.
Sounds like a good adjustment. My initial problem in my project was that I couldn't prevent the entire file / request body from being read. I want to send the body directly to AWS S3 without consuming much memory in my application.
Example:
const command = new PutObjectCommand({
Bucket: "test-bucket",
Key: "test.bin",
Body: Readable.fromWeb(body)
});
await s3Client.send(command);
What version of Bun is running?
1.1.17+bb66bba1b
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What steps can reproduce the bug?
Setting up a simple http server with bun
Send a large file
curl --data-binary "@./1GB.bin" http://localhost:3000
What is the expected behavior?
As with NodeJS, the server does not use much RAM, because nothing is read from the body and saved in a variable.
What do you see instead?
The RAM of the server has increased by the size of the uploaded file.
Additional information
No response