From a70d0df7c99b83a855309606ef310de89afb5ddd Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Thu, 22 Feb 2024 13:02:37 -0300 Subject: [PATCH] revert stuff until the fix is actually ready --- src/bun.js/api/server.zig | 19 +++++++++---------- src/bun.js/webcore/body.zig | 22 +++++++++++----------- src/bun.js/webcore/streams.zig | 8 ++++---- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 32ae10be2c..eafee2f0b2 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2197,7 +2197,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp var this = pair.this; var stream = pair.stream; if (this.resp == null or this.flags.aborted) { - // stream.value.unprotect(); + stream.value.unprotect(); this.finalizeForAbort(); return; } @@ -2265,7 +2265,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp response_stream.sink.destroy(); this.endStream(this.shouldCloseConnection()); this.finalize(); - // stream.value.unprotect(); + stream.value.unprotect(); return; } @@ -2294,7 +2294,6 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp .global = globalThis, }, }; - stream.incrementCount(); assignment_result.then( globalThis, this, @@ -2306,13 +2305,13 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp }, .Fulfilled => { streamLog("promise Fulfilled", .{}); - // defer stream.value.unprotect(); + defer stream.value.unprotect(); this.handleResolveStream(); }, .Rejected => { streamLog("promise Rejected", .{}); - // defer stream.value.unprotect(); + defer stream.value.unprotect(); this.handleRejectStream(globalThis, promise.result(globalThis.vm())); }, @@ -2332,7 +2331,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (this.flags.aborted) { response_stream.detach(); stream.cancel(globalThis); - // defer stream.value.unprotect(); + defer stream.value.unprotect(); response_stream.sink.markDone(); this.finalizeForAbort(); response_stream.sink.onFirstWrite = null; @@ -2342,7 +2341,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp } stream.value.ensureStillAlive(); - // defer stream.value.unprotect(); + defer stream.value.unprotect(); const is_in_progress = response_stream.sink.has_backpressure or !(response_stream.sink.wrote == 0 and response_stream.sink.buffer.len == 0); @@ -2559,7 +2558,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (req.response_ptr) |resp| { if (resp.body.value == .Locked) { - resp.body.value.Locked.readable.?.done(req.server.globalThis); + resp.body.value.Locked.readable.?.done(); resp.body.value = .{ .Used = {} }; } } @@ -2619,7 +2618,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp if (req.response_ptr) |resp| { if (resp.body.value == .Locked) { - resp.body.value.Locked.readable.?.done(req.server.globalThis); + resp.body.value.Locked.readable.?.done(); resp.body.value = .{ .Used = {} }; } } @@ -2693,7 +2692,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp .code = bun.String.static(@as(string, @tagName(JSC.Node.ErrorCode.ERR_STREAM_CANNOT_PIPE))), .message = bun.String.static("Stream already used, please create a new one"), }; - // stream.value.unprotect(); + stream.value.unprotect(); this.runErrorHandler(err.toErrorInstance(this.server.globalThis)); return; } diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index 4b76f1e0ee..b98999929e 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -167,12 +167,12 @@ pub const Body = struct { if (value.onStartBuffering != null) { if (readable.isDisturbed(globalThis)) { form_data.?.deinit(); - readable.detachIfPossible(globalThis); + readable.value.unprotect(); value.readable = null; value.action = .{ .none = {} }; return JSC.JSPromise.rejectedPromiseValue(globalThis, globalThis.createErrorInstance("ReadableStream is already used", .{})); } else { - readable.detachIfPossible(globalThis); + readable.value.unprotect(); value.readable = null; } @@ -191,7 +191,7 @@ pub const Body = struct { else => unreachable, }; value.promise.?.ensureStillAlive(); - readable.detachIfPossible(globalThis); + readable.value.unprotect(); // js now owns the memory value.readable = null; @@ -394,7 +394,7 @@ pub const Body = struct { }, }; - this.Locked.readable.?.incrementCount(); + this.Locked.readable.?.value.protect(); return value; }, @@ -443,7 +443,7 @@ pub const Body = struct { .ptr = .{ .Bytes = &reader.context }, .value = reader.toReadableStream(globalThis), }; - locked.readable.?.incrementCount(); + locked.readable.?.value.protect(); if (locked.onReadableStreamAvailable) |onReadableStreamAvailable| { onReadableStreamAvailable(locked.task.?, locked.readable.?); @@ -581,7 +581,7 @@ pub const Body = struct { } pub fn fromReadableStreamWithoutLockCheck(readable: JSC.WebCore.ReadableStream, globalThis: *JSGlobalObject) Value { - readable.incrementCount(); + readable.value.protect(); return .{ .Locked = .{ .readable = readable, @@ -595,7 +595,7 @@ pub const Body = struct { if (to_resolve.* == .Locked) { var locked = &to_resolve.Locked; if (locked.readable) |readable| { - readable.done(global); + readable.done(); locked.readable = null; } @@ -814,7 +814,7 @@ pub const Body = struct { } if (locked.readable) |readable| { - readable.done(global); + readable.done(); locked.readable = null; } // will be unprotected by body value deinit @@ -855,7 +855,7 @@ pub const Body = struct { this.Locked.deinit = true; if (this.Locked.readable) |*readable| { - readable.done(this.Locked.global); + readable.done(); } } @@ -1361,12 +1361,12 @@ pub const BodyValueBufferer = struct { ); }, .Fulfilled => { - // defer stream.value.unprotect(); + defer stream.value.unprotect(); sink.handleResolveStream(false); }, .Rejected => { - // defer stream.value.unprotect(); + defer stream.value.unprotect(); sink.handleRejectStream(promise.result(globalThis.vm()), false); }, diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index a11f69e306..b737bd79f8 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -155,20 +155,20 @@ pub const ReadableStream = struct { return null; } - pub fn done(this: *const ReadableStream, globalThis: *JSGlobalObject) void { - this.detachIfPossible(globalThis); + pub fn done(this: *const ReadableStream) void { + this.value.unprotect(); } pub fn cancel(this: *const ReadableStream, globalThis: *JSGlobalObject) void { JSC.markBinding(@src()); ReadableStream__cancel(this.value, globalThis); - this.detachIfPossible(globalThis); + this.value.unprotect(); } pub fn abort(this: *const ReadableStream, globalThis: *JSGlobalObject) void { JSC.markBinding(@src()); ReadableStream__cancel(this.value, globalThis); - this.detachIfPossible(globalThis); + this.value.unprotect(); } pub fn forceDetach(this: *const ReadableStream, globalObject: *JSGlobalObject) void {