mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
fix(Server) check before downgrade (#22726)
### What does this PR do? This fix assertion in debug mode, remove flag `has_js_deinited` since js_value is tagged with finalized and is more reliable ### How did you verify your code works? run `bun-debug test test/js/bun/http/serve.test.ts` <img width="514" height="217" alt="Screenshot 2025-09-16 at 14 51 40" src="https://github.com/user-attachments/assets/6a0e9d9a-eb98-4602-8c62-403a77dfcf76" />
This commit is contained in:
@@ -548,10 +548,9 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
|
||||
cached_hostname: bun.String = bun.String.empty,
|
||||
|
||||
flags: packed struct(u4) {
|
||||
flags: packed struct(u3) {
|
||||
deinit_scheduled: bool = false,
|
||||
terminated: bool = false,
|
||||
has_js_deinited: bool = false,
|
||||
has_handled_all_closed_promise: bool = false,
|
||||
} = .{},
|
||||
|
||||
@@ -1427,7 +1426,6 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
pub fn finalize(this: *ThisServer) void {
|
||||
httplog("finalize", .{});
|
||||
this.js_value.finalize();
|
||||
this.flags.has_js_deinited = true;
|
||||
this.deinitIfWeCan();
|
||||
}
|
||||
|
||||
@@ -1460,7 +1458,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
if (this.hasActiveWebSockets()) "active" else "no",
|
||||
this.flags.has_handled_all_closed_promise,
|
||||
if (this.all_closed_promise.strong.has()) "has" else "no",
|
||||
this.flags.has_js_deinited,
|
||||
this.js_value == .finalized,
|
||||
});
|
||||
|
||||
const vm = this.globalThis.bunVM();
|
||||
@@ -1510,7 +1508,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
}
|
||||
|
||||
// Only free the memory if the JS reference has been freed too
|
||||
if (this.flags.has_js_deinited) {
|
||||
if (this.js_value == .finalized) {
|
||||
this.scheduleDeinit();
|
||||
}
|
||||
}
|
||||
@@ -1539,8 +1537,9 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
}
|
||||
|
||||
pub fn stop(this: *ThisServer, abrupt: bool) void {
|
||||
this.js_value.downgrade();
|
||||
|
||||
if (this.js_value.isNotEmpty()) {
|
||||
this.js_value.downgrade();
|
||||
}
|
||||
if (this.config.allow_hot and this.config.id.len > 0) {
|
||||
if (this.globalThis.bunVM().hotMap()) |hot| {
|
||||
hot.remove(this.config.id);
|
||||
|
||||
Reference in New Issue
Block a user