Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server crashes when an invalid Websocket frame is sent. #18

Closed
zotoli opened this issue Apr 8, 2021 · 1 comment
Closed

Server crashes when an invalid Websocket frame is sent. #18

zotoli opened this issue Apr 8, 2021 · 1 comment

Comments

@zotoli
Copy link

zotoli commented Apr 8, 2021

Discovered this while trying to close the socket. If the status code sent is invalid the server crashes. Node.js version is 15.7.0.

This closed issue: websockets/ws#1777 suggests there needs to be a listener for the 'error' event:

wss.on('connection', function connection(ws) {
  ws.on('error', console.error);

  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.send('something');
});

Error message:

node:events:356
      throw er; // Unhandled 'error' event
      ^

RangeError: Invalid WebSocket frame: invalid status code 9
    at Receiver.controlMessage (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/receiver.js:463:18)
    at Receiver.getData (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/receiver.js:349:42)
    at Receiver.startLoop (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/receiver.js:142:22)
    at Receiver._write (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/receiver.js:77:10)
    at writeOrBuffer (node:internal/streams/writable:400:12)
    at _write (node:internal/streams/writable:341:10)
    at Receiver.Writable.write (node:internal/streams/writable:345:10)
    at Socket.socketOnData (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/websocket.js:875:35)
    at Socket.emit (node:events:379:20)
    at addChunk (node:internal/streams/readable:313:12)
Emitted 'error' event on WebSocket instance at:
    at Receiver.receiverOnError (/home/can/nrg_ws/MR_ws/robofleet/robofleet_server/node_modules/ws/lib/websocket.js:780:13)
    at Receiver.emit (node:events:379:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  [Symbol(status-code)]: 1002
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@zotoli
Copy link
Author

zotoli commented Apr 8, 2021

Confirmed this change fixes the crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants