fix: stream Bun runtime downloads to disk to avoid Bun.write GC hang (#44572)

This commit is contained in:
Luke Parker 2026-08-24 11:22:42 +10:00 committed by GitHub
parent 6d57667168
commit 378a7b7be1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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