Repository navigation
Description
What version of Bun is running?
1.3.11
What platform is your computer?
macOS host: Darwin 24.6.0 arm64 arm, Linux container: Linux 6.17.8-orbstack-00308-g8f9c941121b1 aarch64 unknown
What steps can reproduce the bug?
I’m seeing large RSS growth from repeated Bun.S3File.arrayBuffer() calls in a minimal Linux container repro.
What is the expected behavior?
Expected behavior
Repeated Bun.S3File.arrayBuffer() calls on the same object should not cause sustained RSS growth toward OOM after forced GC. RSS should remain bounded or return close to baseline after the temporary buffers are no longer referenced.
What do you see instead?
Observed behavior
The repro prints structured output like:
REPRO_START {...}
REPRO_BASELINE {...}
REPRO_PROGRESS {...}
REPRO_PROGRESS {...}
REPRO_THRESHOLD_REACHED {...}
On Bun 1.3.11, it reliably crosses the configured 900 MiB RSS threshold inside the 1 GiB container.
Example output:
REPRO_START {"bun_version":"1.3.11","platform":"linux","arch":"arm64","payload_mib":8,"target_rss_mib":900,"cgroup_memory_limit_bytes":1073741824,...}
REPRO_BASELINE {"rss_bytes":65523712,...}
REPRO_PROGRESS {"iteration":88,"rss_bytes":877965312,...}
REPRO_THRESHOLD_REACHED {"iteration":95,"rss_bytes":945467392,"target_rss_bytes":943718400,...}
The repro forces Bun.gc(true) after every iteration, but RSS still climbs.
The printed fields include:
rss_bytesheap_total_bytesheap_used_bytesexternal_bytesarray_buffers_bytescgroup_memory_limit_bytescgroup_memory_current_bytes
In my runs, RSS grows far beyond what the JS-managed memory suggests.
Actual OOM verification
If I continue beyond the threshold:
PAYLOAD_MIB=8 TARGET_RSS_MIB=900 MAX_ITERATIONS=4096 REPORT_EVERY=4 EXIT_ON_THRESHOLD=0 bash run.shthe same Bun 1.3.11 repro reaches an actual OOM kill in the 1 GiB container:
DOCKER_EXIT=137
The last printed iterations before the kill showed RSS still climbing past the container limit boundary, for example:
REPRO_THRESHOLD_REACHED {"iteration":100,"rss_bytes":1011945472,...}
REPRO_THRESHOLD_REACHED {"iteration":103,"rss_bytes":1037668352,...}
REPRO_PROGRESS {"iteration":108,"rss_bytes":1044312064,...}
DOCKER_EXIT=137
Additional information
Why this matters
This pattern maps directly to real application code that does:
return new Uint8Array(await body.arrayBuffer());In a long-lived Bun server, this appears to accumulate anonymous RSS even when:
- JS heap remains much smaller
- buffers are not intentionally retained
- GC is forced repeatedly
Related issues
- Memory leak when downloading file (both @google-cloud/storage and Bun's S3) #20487 Memory leak when downloading file (both @google-cloud/storage and Bun's S3)
- Blob/ArrayBuffer memory not reclaimed by GC after dereferencing #28741 Blob/ArrayBuffer memory not reclaimed by GC after dereferencing
- Memory Leak with Blob/ArrayBuffer and Bun's Garbage Collection #12941 Memory Leak with Blob/ArrayBuffer and Bun's Garbage Collection
- Memory is not getting freed after reading multiple files (Node:fs and Bun.File) #15020 Memory is not getting freed after reading multiple files (Node:fs and Bun.File)
This repro is narrower than those reports because it isolates the built-in Bun S3 API directly:
Bun.S3ClientBun.S3File.arrayBuffer()
Additional note
I checked Bun’s public type surface and did not find an explicit cleanup/finalizer API such as close(), destroy(), dispose(), or finalize() on S3File or S3Client for this code path.
Activity
robobun commentedon Apr 9, 2026
🔧 c02d478 (comment-only path fix) —
debian-13-x64-asan-test-bunshows 7 retry successes followed by 1 later failure. Classic flake on a retry; my commit was a single-word path change in a comment, which cannot cause a test failure. claude[bot] also flagged a pre-existing multipart cancel-race leak instartMultiPartRequestResult; they explicitly marked it non-blocking and "fine to leave for a follow-up", so leaving it for a separate PR to keep this ones scope from ballooning further.github-actions commentedon Apr 9, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
sorenbs commentedon Apr 9, 2026
We addressed this issue by implementing a simple R3 client over
fetchfix(s3): free native download body in S3BlobDownloadTask
fix(s3): free native download body in S3BlobDownloadTask
test(s3 leak): restrict to linux-x64 to match existing S3 leak coverage
piazzatron commentedon Apr 14, 2026
I suspect this issue is not limited to
Bun.S3File.arrayBuffer(), but rather may be a more systemic GC issue with Bun's handling ofarrayBuffers. See #28741fix(s3): free native download body in S3BlobDownloadTask
test(s3 leak): restrict to linux-x64 to match existing S3 leak coverage
fix(s3): free native download body in S3BlobDownloadTask
test(s3 leak): restrict to linux-x64 to match existing S3 leak coverage
sorenbs commentedon May 18, 2026
This seem to be fixed by the Rust rewrite 🎉
Codex:
Stable (1.3.14) reproduces both threshold crossing and actual OOM kill. I’ll run the same two commands on canary now with no script changes.
Canary behavior is materially different: with the same default script, RSS stayed near ~100MB and never hit the 900MB threshold. I’m now running the 4096-iteration OOM variant on canary to confirm it remains bounded.
Full report from Codex
Issue Reproduced Report:
#29083Source
I saved exact copies here:
SHA-256:
run.sh:11bc91f9b6df726235a5c16f583afbdd334966034c4d18a7063388d293c7c91brepro.ts:ac1b34c179967b2a79b6304bd00e04210376fe96ac025c15a35b9b1f633e9dd4Test Environment
Darwin 24.6.0 arm64 arm--memory=1g --memory-swap=1grun.shVersions Tested
oven/bun:latestbun --version:1.3.14bun --revision:1.3.14+0d9b296afsha256:e10577f0db68676a7024391c6e5cb4b879ebd17188ab750cf10024a6d700e5c4oven/bun:canarybun --version:1.3.14bun --revision:1.3.14-canary.1+172afa532sha256:a33d83fb11037dc2b4849cbe8af01333b2a469fdf66202d2cb7ed3f9a459def0oven/buntagsStable (
oven/bun:latest) Results1) Issue default repro command
cd /Users/sorenschmidt/code/bun-mem/issue-29083 BUN_IMAGE=oven/bun:latest ./run.shObserved:
96rss_bytes=945,741,824(901.9 MiB) vs target900 MiB0(expected becauseEXIT_ON_THRESHOLD=1)Log: stable-default.log
2) Issue OOM verification command
cd /Users/sorenschmidt/code/bun-mem/issue-29083 BUN_IMAGE=oven/bun:latest PAYLOAD_MIB=8 TARGET_RSS_MIB=900 \ MAX_ITERATIONS=4096 REPORT_EVERY=4 EXIT_ON_THRESHOLD=0 ./run.shObserved:
97(905.0 MiB)rss_bytes=1,111,687,168(1060.2 MiB) before kill1,072,103,424bytes (1022.4 MiB)137(OOM kill)Log: stable-4096-report4.log
Canary (
oven/bun:canary) Results1) Default repro command
cd /Users/sorenschmidt/code/bun-mem/issue-29083 BUN_IMAGE=oven/bun:canary ./run.shObserved:
103,833,600(99.0 MiB)256iterations1withREPRO_THRESHOLD_NOT_REACHED(expected for this script path)Log: canary-default.log
2) Exact issue OOM verification command
cd /Users/sorenschmidt/code/bun-mem/issue-29083 BUN_IMAGE=oven/bun:canary PAYLOAD_MIB=8 TARGET_RSS_MIB=900 \ MAX_ITERATIONS=4096 REPORT_EVERY=4 EXIT_ON_THRESHOLD=0 ./run.shObserved:
4096iterations124,084,224(118.3 MiB)165,421,056(157.8 MiB)1withREPRO_THRESHOLD_NOT_REACHED(no OOM)Log: canary-4096-report4.log
Conclusion
1.3.14+0d9b296af), issue#29083is still reproducible and reaches OOM in the 1 GiB container.1.3.14-canary.1+172afa532), the same repro does not reproduce the leak pattern; RSS remains bounded and no OOM occurs, including the 4096-iteration run.If you want, I can now draft a concise comment for issue
#29083with these exact version/revision/digest details and the stable vs canary comparison.References
alii commentedon May 18, 2026
Great news! Closing this since it sounds like canary fixes it. Please leave a comment if you see otherwise in future, can re-open. Thank you!
fix(corpus): read corpus objects without leaking the download buffer
fix(s3): route every object read off Bun's leaking native download
fix(corpus): read corpus objects without leaking the download buffer
fix(s3): route every object read off Bun's leaking native download
fix(corpus): read corpus objects without leaking the download buffer
fix(s3): route every object read off Bun's leaking native download
fix(s3): route every object read off Bun's leaking native download (#…