From a6745dffc9abca4cebb5d223ecfc90c89746305b Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 5 Oct 2025 06:28:50 +0000 Subject: [PATCH] Add request body abort logic in RequestContext.finalize When a request ends with a pending read on the request body stream, the stream must be aborted to reject the pending read promise. This mirrors the existing response body abort logic but uses the request's this_jsvalue to get the proper owner for the Ref system. --- src/bun.js/api/server/RequestContext.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bun.js/api/server/RequestContext.zig b/src/bun.js/api/server/RequestContext.zig index 27ddb488f1..906539344d 100644 --- a/src/bun.js/api/server/RequestContext.zig +++ b/src/bun.js/api/server/RequestContext.zig @@ -678,6 +678,19 @@ pub fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, any_js_calls = true; } + // Abort request body stream if still locked (e.g., pending read) + if (this.request_weakref.get()) |request| { + if (request.body.value == .Locked) { + const owner: jsc.WebCore.ReadableStream.Ref.Owner = if (request.this_jsvalue.tryGet()) |js_value| + .{ .Request = js_value } + else + .empty; + if (request.body.value.Locked.readable.abort(owner, globalThis)) { + any_js_calls = true; + } + } + } + if (this.response_ptr) |response| { if (response.body.value == .Locked) { if (response.body.value.Locked.readable.abort(.{ .Response = response_jsvalue }, globalThis)) {