From 677b5a5b2653abd786a39b0f959e27de035598e7 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 24 Jun 2026 01:01:46 +0000 Subject: [PATCH 1/4] Remove stale signal.is_dead() assertion in pipe_readable_stream_to_blob The controllerDetached hook added in #32120 clears the sink signal when controller.end()/.close() is called. When a source stream finishes synchronously inside assignToStream (for example an S3 file with no credentials, which throws in pull()), the controller detaches before assignToStream returns and the signal is legitimately dead. The assertion predates that hook; RequestContext.rs already dropped its equivalent assertion with the same reasoning. --- src/runtime/webcore/Blob.rs | 7 ++- .../s3/s3-write-to-file-sync-close.test.ts | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/js/bun/s3/s3-write-to-file-sync-close.test.ts diff --git a/src/runtime/webcore/Blob.rs b/src/runtime/webcore/Blob.rs index 140a6e017ea8..a42dded6d28d 100644 --- a/src/runtime/webcore/Blob.rs +++ b/src/runtime/webcore/Blob.rs @@ -1649,8 +1649,11 @@ impl BlobExt for Blob { assignment_result.ensure_still_alive(); - // assert that it was updated - debug_assert!(!signal.get().is_dead()); + // assignToStream stored the controller's encoded JSValue in + // signal.ptr. If the stream finished synchronously inside the call, + // controller.end()/.close() detached the controller and cleared the + // signal again (`__controllerDetached`), so the signal may be + // legitimately dead here; the branches below handle that state. if let Some(err) = assignment_result.to_error() { // SAFETY: release our +1 ref on the sink. diff --git a/test/js/bun/s3/s3-write-to-file-sync-close.test.ts b/test/js/bun/s3/s3-write-to-file-sync-close.test.ts new file mode 100644 index 000000000000..e561cffd7450 --- /dev/null +++ b/test/js/bun/s3/s3-write-to-file-sync-close.test.ts @@ -0,0 +1,51 @@ +import { expect, test } from "bun:test"; +import { bunEnv, bunExe, normalizeBunSnapshot, tempDir } from "harness"; +import path from "node:path"; + +// Writing an S3 source with no credentials to a file-backed Blob routes +// through pipe_readable_stream_to_blob. The S3 stream's pull() fails +// synchronously with ERR_S3_MISSING_CREDENTIALS, which ends the sink and +// detaches the controller before assignToStream returns. This used to trip a +// debug assertion that the signal was still live. +test("Bun.file().write(S3 file) when the S3 stream closes synchronously", async () => { + using dir = tempDir("s3-write-sync-close", {}); + const dest = path.join(String(dir), "out.bin"); + + const fixture = ` + const s3 = Bun.S3Client.file("key"); + const result = await Bun.file(${JSON.stringify(dest)}).write(s3); + console.log(typeof result); + `; + + await using proc = Bun.spawn({ + cmd: [bunExe(), "-e", fixture], + env: { + ...bunEnv, + S3_ACCESS_KEY_ID: undefined, + S3_SECRET_ACCESS_KEY: undefined, + S3_REGION: undefined, + S3_ENDPOINT: undefined, + S3_BUCKET: undefined, + S3_SESSION_TOKEN: undefined, + AWS_ACCESS_KEY_ID: undefined, + AWS_SECRET_ACCESS_KEY: undefined, + AWS_REGION: undefined, + AWS_ENDPOINT: undefined, + AWS_BUCKET: undefined, + AWS_SESSION_TOKEN: undefined, + }, + stdout: "pipe", + stderr: "pipe", + }); + + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + + expect({ + stdout: normalizeBunSnapshot(stdout), + stderr: normalizeBunSnapshot(stderr), + }).toEqual({ + stdout: "number", + stderr: "", + }); + expect(exitCode).toBe(0); +}); From 617613cf29b89ad4cbd5b392c451210b29c4b872 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 24 Jun 2026 01:11:33 +0000 Subject: [PATCH 2/4] retrigger From fb1212a90dc52b819df605c4e49f944f98c326bd Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 24 Jun 2026 01:34:24 +0000 Subject: [PATCH 3/4] test: accept either resolve or reject so a future fix surfacing the S3 error does not trip this test --- .../s3/s3-write-to-file-sync-close.test.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/js/bun/s3/s3-write-to-file-sync-close.test.ts b/test/js/bun/s3/s3-write-to-file-sync-close.test.ts index e561cffd7450..51afa22d461d 100644 --- a/test/js/bun/s3/s3-write-to-file-sync-close.test.ts +++ b/test/js/bun/s3/s3-write-to-file-sync-close.test.ts @@ -3,18 +3,27 @@ import { bunEnv, bunExe, normalizeBunSnapshot, tempDir } from "harness"; import path from "node:path"; // Writing an S3 source with no credentials to a file-backed Blob routes -// through pipe_readable_stream_to_blob. The S3 stream's pull() fails -// synchronously with ERR_S3_MISSING_CREDENTIALS, which ends the sink and -// detaches the controller before assignToStream returns. This used to trip a -// debug assertion that the signal was still live. +// through pipe_readable_stream_to_blob. The S3 stream fails synchronously +// with ERR_S3_MISSING_CREDENTIALS, which ends the sink and detaches the +// controller before assignToStream returns. This used to trip a debug +// assertion that the signal was still live. +// +// Today the credential error is swallowed by ByteStream::on_start() returning +// Start::Empty without checking pending.result, so write() resolves to 0. +// Accept either outcome here so a future fix that surfaces the error does not +// trip this test. test("Bun.file().write(S3 file) when the S3 stream closes synchronously", async () => { using dir = tempDir("s3-write-sync-close", {}); const dest = path.join(String(dir), "out.bin"); const fixture = ` - const s3 = Bun.S3Client.file("key"); - const result = await Bun.file(${JSON.stringify(dest)}).write(s3); - console.log(typeof result); + try { + const s3 = Bun.S3Client.file("key"); + await Bun.file(${JSON.stringify(dest)}).write(s3); + console.log("resolved"); + } catch (e) { + console.log("rejected:" + (e?.code ?? e?.name ?? "Error")); + } `; await using proc = Bun.spawn({ @@ -43,9 +52,11 @@ test("Bun.file().write(S3 file) when the S3 stream closes synchronously", async expect({ stdout: normalizeBunSnapshot(stdout), stderr: normalizeBunSnapshot(stderr), + signalCode: proc.signalCode, }).toEqual({ - stdout: "number", + stdout: expect.stringMatching(/^(resolved|rejected:ERR_S3_MISSING_CREDENTIALS)$/), stderr: "", + signalCode: null, }); expect(exitCode).toBe(0); }); From 56b0ec0e81acbd8683f2799b18c41d82cd7d0e37 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 24 Jun 2026 18:33:18 -0700 Subject: [PATCH 4/4] Update Blob.rs --- src/runtime/webcore/Blob.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/runtime/webcore/Blob.rs b/src/runtime/webcore/Blob.rs index a42dded6d28d..6acce2470c94 100644 --- a/src/runtime/webcore/Blob.rs +++ b/src/runtime/webcore/Blob.rs @@ -1649,12 +1649,6 @@ impl BlobExt for Blob { assignment_result.ensure_still_alive(); - // assignToStream stored the controller's encoded JSValue in - // signal.ptr. If the stream finished synchronously inside the call, - // controller.end()/.close() detached the controller and cleared the - // signal again (`__controllerDetached`), so the signal may be - // legitimately dead here; the branches below handle that state. - if let Some(err) = assignment_result.to_error() { // SAFETY: release our +1 ref on the sink. unsafe { webcore::FileSink::deref(file_sink) };