Server crashes with Invalid WebSocket frame

See original GitHub issue

Duplicate of closed issue: https://github.com/websockets/ws/issues/1777

Description

The server crashes on an invalid WS frame. I have the impression this is not intended behaviour. I’ve been reading the code at Receiver.controlMessage and Receiver.receiverOnError but can’t seem to find a reason for it to throw an Error besides emitting it. If I would know how to catch this error I could work around the problem.

Reproducible in:

  • Node.js version(s): 12.18.3
  • OS version(s): Ubuntu 20

Steps to reproduce:

Send a 1006 frame to the server

Expected result:

Server emits error

Actual result:

Error thrown and app crashes

Attachments:

events.js:291
      throw er; // Unhandled 'error' event
      ^

RangeError: Invalid WebSocket frame: invalid status code 1006
    at Receiver.controlMessage (/app/node_modules/ws/lib/receiver.js:464:18)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:350:42)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:143:22)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:78:10)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Receiver.Writable.write (_stream_writable.js:318:11)
    at Socket.socketOnData (/app/node_modules/ws/lib/websocket.js:900:35)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

Emitted 'error' event on WebSocket instance at:
    at Receiver.receiverOnError (/app/node_modules/ws/lib/websocket.js:805:13)
    at Receiver.emit (events.js:314:20)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:418:5)
    at onwrite (_stream_writable.js:445:5)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:152:5)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:78:10)
    [... lines matching original stack trace ...]
 {
  [Symbol(status-code)]: 1002
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lpincacommented, Aug 30, 2022

Or is it safe to let the instance get destroyed with the listener attached?

It is ok to keep it attached.

0reactions
lpincacommented, Sep 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server crashes with Invalid WebSocket frame: RSV1 must be ...
Server crashes with Invalid WebSocket frame : RSV1 must be clear.
Read more >
RangeError: Invalid WebSocket frame: RSV1 must be clear
someone keeps trying to crash my WebSocket server, and this error keeps getting sent when they try. Is there any possible fix to...
Read more >
Invalid WebSocket frame: invalid payload length 126
colyseus:errors RangeError: Invalid WebSocket frame: invalid payload ... I see, is this error crashing the server, or it just prints this ...
Read more >
Implementing a Crash-Resistant Socket.io Service Without ...
Since we are using the WebSocket for things like presence badges which require ... However, in the case of a server crash, we...
Read more >
Changelog - Nchan
1 2022) fix: Redis cluster slave failover may result in crash 1.3.3 (Aug. ... group fix: messages published to Nchan via websocket binary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found