You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory Leak When Streaming Responses via fetch in Bun ≥ 1.1.27 #18488
We’ve observed a memory leak when running our thumbnail proxy app under Bun 1.1.27+. The same app in 1.1.26 maintains steady memory usage. In newer versions, memory steadily grows until our container’s OOM killer terminates the process.
Application Workflow
1. Receive an HTTP GET request (via Bun.serve + Hono.js).
2. Perform a fetch to an external CDN to retrieve a thumbnail image.
3. Pipe that Response body back to the client with streaming (using Hono’s stream).
4. On non-200 fetch responses, we call response.body?.cancel() to free resources.
5. On success, we rely on the streaming to complete, and then the fetch response is closed naturally (i.e., once streaming ends).
import { Hono } from 'hono';
import { stream } from 'hono/streaming';
const app = new Hono();
app.get('/proxy', async (c) => {
const url = 'https://example.com/image.jpeg'; // CDN resource
let response: Response;
try {
response = await fetch(url);
} catch (error) {
return c.text('Fetch error', 502);
}
if (!response.ok) {
await response.body?.cancel();
return c.text('Bad response from CDN', 502);
}
// Example of streaming the successful response back
return stream(c, async (streamWriter) => {
try {
return streamWriter.pipe(response.body!);
} catch (error) {
await response.body?.cancel();
throw error;
}
});
});
// Start server
Bun.serve({
fetch: app.fetch,
port: 3000,
});
What is the expected behavior?
• Memory usage should not grow significantly over time.
• After numerous thumbnail requests, the memory usage should stabilize or at least get reclaimed eventually by GC.
What do you see instead?
• Under Bun 1.1.27+, memory grows steadily with every new request.
• It never stabilizes nor is reclaimed by GC, eventually hitting OOM.
• Reverting to Bun 1.1.26 resolves the issue.
Additional information
Here is chart of memory consumption of 2 pods running, before and after container bun version upgrade 1.1.26->1.1.27
Reacted by Matheus Gabriel Werny, ScottUK, Kube and Aluisio Amorim
I am on Bun 1.3 and have almost the same code as Scott. The only difference is, I am using got that uses fetch under the hood.
I am still experiencing the problem.
I am on Debian 12.
It has been a long time with this problem, is there anything we can do to help?
I am on Bun 1.3 and have almost the same code as Scott. The only difference is, I am using got that uses fetch under the hood. I am still experiencing the problem. I am on Debian 12.
It has been a long time with this problem, is there anything we can do to help?
This problem has existed for years, that's why I'm still using Node.js :(
This was likely fixed in Bun v1.3.6 - there was a memory leak in node:zlib (which could impact got) and there was an edgecase involving proxies that could cause ReadableStream from a request body to not get collected.
if you continue to run into this, please file a new issue with a reproduction
Activity
Jarred-Sumner commentedon Mar 26, 2025
Have you tried in Bun v1.2.5?
dmdb commentedon Mar 26, 2025
1.2.5, 1.2.6, 1.2 tried today - same situation
ScottUK commentedon Mar 29, 2025
Could be related to what I saw here?
#16529
I've been running a project that sees this same issue which is essentially a proxy. Streams a response from a different site back to the client.
I've essentially used every version of Bun from 1.1.45 up to 1.2.6, can try 1.2.7 today.
Memory usage looks like this: (It's steady, the different peaks just represent peak usage times for the app as it's in production)

mags-sully commentedon Apr 12, 2025
@ScottUK have you tried 1.2.9?
ScottUK commentedon Apr 12, 2025
Just upgraded services to 1.2.9, will know within a few hours.
ScottUK commentedon Apr 12, 2025
Can confirm still happening.
drag0n-app commentedon Oct 11, 2025
@ScottUK Bun 1.3 has been released. Please test it again.
reyzzz commentedon Oct 23, 2025
I am on Bun 1.3 and have almost the same code as Scott. The only difference is, I am using got that uses fetch under the hood.
I am still experiencing the problem.
I am on Debian 12.
It has been a long time with this problem, is there anything we can do to help?
viktorlarsson commentedon Nov 9, 2025
Still happening on 1.3.0
drag0n-app commentedon Nov 14, 2025
This problem has existed for years, that's why I'm still using Node.js :(
Jarred-Sumner commentedon Jan 13, 2026
This was likely fixed in Bun v1.3.6 - there was a memory leak in node:zlib (which could impact
got) and there was an edgecase involving proxies that could cause ReadableStream from a request body to not get collected.if you continue to run into this, please file a new issue with a reproduction
docs(research): desktop-shell architecture research from feat/desktop…
Stop leaking native memory on Cloud responses and make roster polls c…