diff options
author | 2022-10-17 07:25:10 -0700 | |
---|---|---|
committer | 2022-10-17 07:25:10 -0700 | |
commit | 4bd9b20c8a45f08ac8169e782028d26282d54829 (patch) | |
tree | 83830d14aa99399a2f144fa7d5b5fa1ed7356979 /src | |
parent | 9190061ba4b28dfdb1efafa8a662da2a0809add4 (diff) | |
download | bun-4bd9b20c8a45f08ac8169e782028d26282d54829.tar.gz bun-4bd9b20c8a45f08ac8169e782028d26282d54829.tar.zst bun-4bd9b20c8a45f08ac8169e782028d26282d54829.zip |
Workaround crash
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/server.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 30ba4d714..0cb5d4cd1 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2978,7 +2978,18 @@ pub const ServerWebSocket = struct { return JSValue.jsNumber( // if 0, return 0 // else return number of bytes sent - @as(i32, @boolToInt(this.websocket.publishWithOptions(this.handler.app, topic_slice.slice(), slice, .binary, compress))) * @intCast( + @as( + i32, + @boolToInt( + this.websocket.publishWithOptions( + this.handler.app, + topic_slice.slice(), + slice, + .binary, + compress, + ), + ), + ) * @intCast( i32, @truncate(u31, slice.len), ), @@ -3352,13 +3363,18 @@ pub const ServerWebSocket = struct { return JSValue.jsUndefined(); } + if (!this.opened) { + globalThis.throw("Calling close() inside open() is not supported. Consider changing your upgrade() callback instead", .{}); + return .zero; + } + this.closed = true; + const code = if (args.len > 0) args.ptr[0].toInt32() else @as(i32, 1000); var message_value = if (args.len > 1) args.ptr[1].toSlice(globalThis, bun.default_allocator) else ZigString.Slice.empty; defer message_value.deinit(); if (code > 0) { this.websocket.end(code, message_value.slice()); } else { - this.closed = true; this.this_value.unprotect(); this.websocket.close(); } |