Answer the question
In order to leave comments, you need to log in
Why does the websocket server crash?
WebSocket server runs on nodejs. When I crashed, I noticed the following errors:
Error: not opened
at WebSocket.send (/root/node/node_modules/ws/lib/WebSocket.js:214:16)
at WebSocket.<anonymous> (/root/node/server.js:30:19)
at WebSocket.emit (events.js:112:17)
at Receiver.ontext (/root/node/node_modules/ws/lib/WebSocket.js:797:10)
at /root/node/node_modules/ws/lib/Receiver.js:473:18
at Receiver.applyExtensions (/root/node/node_modules/ws/lib/Receiver.js:360:5)
at /root/node/node_modules/ws/lib/Receiver.js:462:14
at Receiver.flush (/root/node/node_modules/ws/lib/Receiver.js:336:3)
at Receiver.opcodes.1.finish (/root/node/node_modules/ws/lib/Receiver.js:478:12)
at Receiver.expectHandler (/root/node/node_modules/ws/lib/Receiver.js:447:33)
/root/node/node_modules/ws/lib/WebSocket.js:214
else throw new Error('not opened');
^
Error: not opened
at WebSocket.send (/root/node/node_modules/ws/lib/WebSocket.js:214:16)
at WebSocket.<anonymous> (/root/node/server.js:30:19)
at WebSocket.emit (events.js:112:17)
at Receiver.ontext (/root/node/node_modules/ws/lib/WebSocket.js:797:10)
at /root/node/node_modules/ws/lib/Receiver.js:473:18
at /root/node/node_modules/ws/lib/Receiver.js:357:7
at /root/node/node_modules/ws/lib/PerMessageDeflate.js:217:5
at afterWrite (_stream_writable.js:363:3)
at onwrite (_stream_writable.js:354:7)
at WritableState.onwrite (_stream_writable.js:107:5)
Answer the question
In order to leave comments, you need to log in
The problem is that you don't check if the connection is alive before sending data to it. To find the problem, there is not enough stack output depth, add the key when starting the node node --stack-trace-limit=1000 application.js and it will be visible there and from what place in your code it is called. You need to catch ws.on('close', fn) and ws.on('error', fn) and remove these sockets from the set that you loop through and send, you can additionally put a check like if (connection.readyState ===WebSocket.OPEN) ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question