Closed renat2985 closed 1 month ago
Is there anything more you can share with us? The stacktrace says it crashed in a cork
callback in the WebSocket server.
One thing that's a little interesting is that number 0x2
is how JavaScriptCore represents the value null
in JS. This would potentially mean that somewhere we're assuming a value is an object without first checking that it is not null
or undefined
(or otherwise, not a cell).
These are excerpts, hope it helps you.
import { Database } from "bun:sqlite";
const db = Database.open(":memory:");
db.exec('CREATE TABLE "online" ("onlineID" INTEGER, "activity" TEXT, *** , PRIMARY KEY("onlineID" AUTOINCREMENT))');
***
const port = process.env.PORT || 8585;
const server = Bun.serve({
fetch(req, server) {
const url = new URL(req.url);
if (url.search.length == 72) {
server.upgrade(req, {
data: {
name: "none",
room: new URL(req.url).search.split("?")[1].split("&")[0].replace(/[^a-zA-Z0-9]/g, ''),
mac: new URL(req.url).search.split("?")[1].split("&")[1].replace(/[^a-zA-Z0-9:]/g, ''),
pid: Math.floor(Math.random() * (9999999 - 1000000 + 1)) + 1000000
},
})
}
***
port: port,
websocket: {
open(ws) {
ws.subscribe(ws.data.room);
ws.send(`Enter name:`);
},
message(ws, msg) {
var dateString = viewDateTime();
***
if (ws.data.name == "none") {
ws.data.name = msg;
msg = `joined`;
ws.send(`[${dateString}] Welcome to the control ${ws.data.name}!`);
console.log(dateString+' Connect: ' + ws.data.room + ' ' + ws.data.mac + ' ' + ws.data.pid + ' ' + ws.data.name);
***
const result = db.query(`SELECT * FROM online WHERE room = '${ws.data.room}' AND mac = '${ws.data.mac}'`).get();
db.query(`DELETE FROM online *** `).get();
}
db.query(`INSERT INTO online *** `).get();
}
***
}
const out = `[${dateString}] ${ws.data.name} ${msg}`;
ws.publishText(ws.data.room, out);
ws.send(out);
},
close(ws, code, message) {
var dateString = viewDateTime();
const out = `[${dateString}] ${ws.data.name} disconnect`;
ws.unsubscribe(ws.data.room);
server.publish(ws.data.room, out);
***
db.query(`DELETE FROM online *** ');
delete ws.data;
},
perMessageDeflate: false,
idleTimeout: 60, // 900 = 15min default: 120 (seconds)
},
});
Oh, I wonder if it's delete ws.data
. If you instead ws.data = null
or ws.data = undefined
, does that help?
Ok, thanks.
replace delete ws.data
with ws.data = null
unfortunately this did not help.
Friday we added some fixes on server.zig, can you try bun upgrade --canary
if is still happening?
How can we reproduce the crash?
This is not a server resource issue. This is a fairly powerful Amazon cloud server that runs only bun, serves about 200 WebSoscket connections...
Relevant log output
Stack Trace (bun.report)
Bun v1.1.13 (
bd6a605
) on linux x86_64 [AutoCommand]Segmentation fault at address 0x00000002
ld-temp.o:0
:WTF::jscSignalHandler
??
ld-temp.o:0
:llint_call_javascript
ld-temp.o:0
:JSC::Interpreter::executeCall
ld-temp.o:0
:JSC::profiledCall
bindings.cpp:2285
:JSObjectCallAsFunctionReturnValue
server.zig:0
:src.deps.uws.AnyWebSocket.cork__anon_347613.Wrapper.wrap
MoveOnlyFunction.h:247
:uws_ws_cork
uws.zig:0
:src.deps.uws.WebSocketBehavior.Wrap
MoveOnlyFunction.h:247
:uWS::WebSocketContext<false, true, void*>::handleFragment