Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ JSPromise* readableStreamCancel(JSGlobalObject* globalObject, JSReadableStream*
pendingRead->fulfill(vm, doneResult);
RETURN_IF_EXCEPTION(scope, nullptr);
}
controller->m_closed = true;
// m_closed is NOT set here: a write()/end() captured by an in-flight pull() must not
// throw after a consumer-side cancel (Bun v1.3.x behavior). onClose early-returns on
// stream state, and handleError's callees all tolerate the cleared source below.
Comment thread
robobun marked this conversation as resolved.
Resolved
directStreamControllerClearSource(controller);
sourceCancelPromise = promiseFulfilledWith(globalObject, JSC::jsUndefined());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ test("ReadableStream releases source-only WriteBarriers once terminal", async ()
expect(exitCode).toBe(0);
});

// readableStreamCancel's Direct arm used to leave m_closed false (onClose early-returned
// because the stream was already Closed), so a captured controller could still reach
// writeToDirectSink after cancel. With m_closed set, the bound methods throw.
test("direct controller write() after reader.cancel() throws closed", async () => {
// readableStreamCancel's Direct arm must not set m_closed: a producer whose async pull()
// outlives a consumer-side cancel() still holds the bound controller, and its late
// write()/end() are no-ops that do not throw (Bun v1.3.x behavior). #36703 briefly made
// this throw; this test pins the non-throwing contract.
test("direct controller write() after reader.cancel() does not throw", async () => {
let ctrl: any;
let pullStarted = Promise.withResolvers<void>();
const rs = new ReadableStream({
Expand All @@ -115,5 +116,8 @@ test("direct controller write() after reader.cancel() throws closed", async () =
reader.read().catch(() => {});
await pullStarted.promise;
await reader.cancel();
expect(() => ctrl.write("after-cancel")).toThrow(/closed/);
expect(ctrl.write("after-cancel")).toBe("after-cancel".length);
expect(() => ctrl.end()).not.toThrow();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
expect(() => ctrl.flush()).not.toThrow();
expect(() => ctrl.error(new Error("after-cancel"))).not.toThrow();
});
Loading