From 378a7b7be131997749a8359b373937702912ee1a Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Mon, 24 Aug 2026 11:22:42 +1000 Subject: [PATCH] fix: stream Bun runtime downloads to disk to avoid Bun.write GC hang (#44572) --- packages/cli/script/build.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/script/build.ts b/packages/cli/script/build.ts index 609327757ee..eae30d83b78 100755 --- a/packages/cli/script/build.ts +++ b/packages/cli/script/build.ts @@ -185,7 +185,11 @@ async function compileExecutable(item: (typeof allTargets)[number]) { headers: { Accept: "application/octet-stream", ...(token ? { Authorization: `Bearer ${token}` } : {}) }, }) if (!response.ok) throw new Error(`Failed to download ${name} from Bun release ${release}: ${response.status}`) - await Bun.write(archive, response) + // Stream to disk instead of `Bun.write(archive, response)`: passing the Response object + // hangs forever if it gets GC'd mid-download (https://github.com/oven-sh/bun/issues/40278). + const sink = Bun.file(archive).writer() + for await (const chunk of response.body!) await sink.write(chunk) + await sink.end() await $`unzip -oq ${archive} -d ${cache}` await rm(archive) return executable