diff options
author | 2023-05-21 14:29:02 -0700 | |
---|---|---|
committer | 2023-05-21 14:29:02 -0700 | |
commit | b33f20d51b728137bf38b69b82fd481c4a0f6fc8 (patch) | |
tree | 76aba6139c7f0d9a4191a27d8849bab37ff58727 | |
parent | 1e307e7690d4e21304a51a197324c087289d3646 (diff) | |
download | bun-b33f20d51b728137bf38b69b82fd481c4a0f6fc8.tar.gz bun-b33f20d51b728137bf38b69b82fd481c4a0f6fc8.tar.zst bun-b33f20d51b728137bf38b69b82fd481c4a0f6fc8.zip |
[internal] Make AbortSIgnal usage slightly safer
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 5 | ||||
-rw-r--r-- | src/bun.js/webcore/response.zig | 10 | ||||
-rw-r--r-- | src/http_client_async.zig | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index a97ce3935..c6c71765a 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -1816,6 +1816,11 @@ pub const AbortSignal = extern opaque { return cppFn("unref", .{this}); } + pub fn detach(this: *AbortSignal, ctx: ?*anyopaque) void { + _ = this.unref(); + this.cleanNativeBindings(ctx); + } + pub fn fromJS(value: JSValue) ?*AbortSignal { return cppFn("fromJS", .{value}); } diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index d283df5a0..e9e6e2df2 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -659,18 +659,18 @@ pub const Fetch = struct { this.request_headers.entries.deinit(bun.default_allocator); this.request_headers.buf.deinit(bun.default_allocator); this.request_headers = Headers{ .allocator = undefined }; - this.http.?.deinit(); + this.http.?.clearData(); this.result.deinitMetadata(); this.response_buffer.deinit(); this.request_body.detach(); - if (this.abort_reason != .zero) this.abort_reason.unprotect(); + if (this.abort_reason != .zero) + this.abort_reason.unprotect(); if (this.signal) |signal| { - signal.cleanNativeBindings(this); - _ = signal.unref(); this.signal = null; + signal.detach(this); } } @@ -720,8 +720,8 @@ pub const Fetch = struct { pub fn onReject(this: *FetchTasklet) JSValue { if (this.signal) |signal| { - _ = signal.unref(); this.signal = null; + signal.detach(this); } if (!this.abort_reason.isEmptyOrUndefinedOrNull()) { diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 276186fe5..370037db9 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -1247,7 +1247,7 @@ pub const AsyncHTTP = struct { } } - pub fn deinit(this: *AsyncHTTP) void { + pub fn clearData(this: *AsyncHTTP) void { this.response_headers.deinit(this.allocator); this.response_headers = .{}; this.request = null; |