mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix: Set websocketServerContext field after server toJS()
Move the websocketServerContextSetCached call from listen() to BunObject.serve(), right after toJS() creates the server JSValue. This ensures: 1. The server JSValue exists before we try to set fields on it 2. The websocket context is stored in the correct place alongside routeList 3. The GC can properly track the relationship
This commit is contained in:
@@ -1086,6 +1086,9 @@ pub fn serve(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.J
|
||||
if (route_list_object != .zero) {
|
||||
ServerType.js.routeListSetCached(obj, globalObject, route_list_object);
|
||||
}
|
||||
if (config.websocket_js_context != .zero) {
|
||||
ServerType.js.websocketServerContextSetCached(obj, globalObject, config.websocket_js_context);
|
||||
}
|
||||
server.js_value.setStrong(obj, globalObject);
|
||||
|
||||
if (config.allow_hot) {
|
||||
|
||||
@@ -2726,14 +2726,6 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
|
||||
httplog("listen", .{});
|
||||
var app: *App = undefined;
|
||||
const globalThis = this.globalThis;
|
||||
|
||||
// Set the websocketServerContext on the server JSValue to keep it alive through GC
|
||||
if (this.config.websocket_js_context != .zero) {
|
||||
const server_value = this.jsValueAssertAlive();
|
||||
const js = bun.JSC.Codegen.JSHTTPServerClass(comptime protocol, comptime development);
|
||||
js.websocketServerContextSetCachedValue(server_value, globalThis, this.config.websocket_js_context);
|
||||
}
|
||||
|
||||
var route_list_value = jsc.JSValue.zero;
|
||||
if (ssl_enabled) {
|
||||
bun.BoringSSL.load();
|
||||
|
||||
Reference in New Issue
Block a user