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

Memory accumulation and crash when calling fetch() with Blob in FormData running in Docker #13657

Closed mshameti closed 2 months ago

mshameti commented 2 months ago

What version of Bun is running?

1.1.26+0a37423ba

What platform is your computer?

Linux 6.6.16-linuxkit aarch64

What steps can reproduce the bug?

Code snippet: https://github.com/mshameti/bun-memory-accumulation-formdata-fetch-docker/blob/main/sender/script.js

git clone https://github.com/mshameti/bun-memory-accumulation-formdata-fetch-docker
cd bun-memory-accumulation-formdata-fetch-docker
docker-compose up --build

What is the expected behavior?

No memory accumulation when sending Blobs in FormData with fetch() in Docker.

What do you see instead?

Memory accumulates until container runs out of memory.

Additional information

Container exits with code 137 when it runs out of memory.

Potentially related: https://github.com/oven-sh/bun/issues/5507

Jarred-Sumner commented 2 months ago

This code isn’t waiting for the response to finish receiving the body before starting the next request. If you await response.blob() or similar does that reduce memory usage?

shametim commented 2 months ago

Thanks for taking a look! It did not reduce memory usage unfortunately.

I thought I had included that as part of the commented code of things that I tried, will update the repo example later tonight.

mshameti commented 2 months ago

updated example

Jarred-Sumner commented 2 months ago

Will have a fix shortly.