aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/api/server.zig10
-rw-r--r--test/js/node/http/node-http.test.ts16
2 files changed, 21 insertions, 5 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 64a85d6a4..ca803cef2 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -1023,7 +1023,7 @@ fn NewFlags(comptime debug_mode: bool) type {
has_written_status: bool = false,
response_protected: bool = false,
aborted: bool = false,
- finalized: bun.DebugOnly(bool) = bun.DebugOnlyDefault(false),
+ has_finalized: bun.DebugOnly(bool) = bun.DebugOnlyDefault(false),
};
}
@@ -1515,9 +1515,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
ctxLog("finalizeWithoutDeinit<d> ({*})<r>", .{this});
this.blob.detach();
- if (comptime Environment.allow_assert) {
- std.debug.assert(!this.flags.finalized);
- this.flags.finalized = true;
+ if (comptime Environment.isDebug) {
+ ctxLog("finalizeWithoutDeinit: has_finalized {any}", .{this.flags.has_finalized});
+ this.flags.has_finalized = true;
}
if (!this.response_jsvalue.isEmpty()) {
@@ -1596,7 +1596,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
ctxLog("deinit<d> ({*})<r>", .{this});
if (comptime Environment.allow_assert)
- std.debug.assert(this.flags.finalized);
+ std.debug.assert(this.flags.has_finalized);
if (comptime Environment.allow_assert)
std.debug.assert(this.flags.has_marked_complete);
diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts
index 6dca23547..3a654c393 100644
--- a/test/js/node/http/node-http.test.ts
+++ b/test/js/node/http/node-http.test.ts
@@ -750,4 +750,20 @@ describe("node:http", () => {
}
});
});
+
+ test("test server internal error, issue#4298", done => {
+ const server = createServer((req, res) => {
+ throw Error("throw an error here.");
+ });
+ server.listen({ port: 0 }, async (_err, host, port) => {
+ try {
+ await fetch(`http://${host}:${port}`).then(res => {
+ expect(res.status).toBe(500);
+ done();
+ });
+ } catch (err) {
+ done(err);
+ }
+ });
+ });
});