aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-03-01 20:47:04 -0300
committerGravatar GitHub <noreply@github.com> 2023-03-01 15:47:04 -0800
commit1227a7b995d02980634ded567a4a233c1ddd26a2 (patch)
treec514a447b1741007f6839b2dade635e9a41a1421
parentef569610071e37e763579b2408e549e09cf1119a (diff)
downloadbun-1227a7b995d02980634ded567a4a233c1ddd26a2.tar.gz
bun-1227a7b995d02980634ded567a4a233c1ddd26a2.tar.zst
bun-1227a7b995d02980634ded567a4a233c1ddd26a2.zip
avoids segfault after aborted onReject in Bun.serve streams (#2256)
* avoids segfault after aborted on reject * silence err on handleRejectStream after aborted
-rw-r--r--src/bun.js/api/server.zig15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 3a9a31ec9..daa028d39 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -1088,7 +1088,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
std.debug.assert(!this.finalized);
this.finalized = true;
}
-
+
if (!this.response_jsvalue.isEmpty()) {
ctxLog("finalizeWithoutDeinit: response_jsvalue != .zero", .{});
if (this.response_protected) {
@@ -1817,8 +1817,8 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
pub fn handleResolveStream(req: *RequestContext) void {
streamLog("handleResolveStream", .{});
//aborted already called finalizeForAbort at this stage
- if(req.aborted) return;
-
+ if (req.aborted) return;
+
var wrote_anything = false;
if (req.sink) |wrapper| {
wrapper.sink.pending_flush = null;
@@ -1837,7 +1837,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
resp.body.value = .{ .Used = {} };
}
}
-
+
const responded = req.resp.hasResponded();
if (!responded and !wrote_anything) {
@@ -1848,7 +1848,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
req.resp.clearAborted();
req.resp.endStream(req.shouldCloseConnection());
}
-
+
req.finalize();
}
@@ -1869,6 +1869,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
pub fn handleRejectStream(req: *@This(), globalThis: *JSC.JSGlobalObject, err: JSValue) void {
+ //aborted already called finalizeForAbort at this stage
+ if (req.aborted) return;
+
streamLog("handleRejectStream", .{});
var wrote_anything = req.has_written_status;
@@ -1906,8 +1909,6 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
req.server.vm.runErrorHandler(err, &exception_list);
}
}
- //aborted already called finalizeForAbort at this stage
- if(req.aborted) return;
req.finalize();
return;
}