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

How to interpret error messge #1662

Closed
aeolus opened this issue Nov 19, 2019 · 2 comments
Closed

How to interpret error messge #1662

aeolus opened this issue Nov 19, 2019 · 2 comments

Comments

@aeolus
Copy link

aeolus commented Nov 19, 2019

Hi, our service recently throws a websocket exception from time to time. The error itself is like this:

Invalid WebSocket frame: invalid payload length 126

Now I manage to print the error as a json. My question is there any way to interpret this error message. The buffers array looks like a decimal array to me but I failed to decode it to any useful context and I don't know what the usage for mask here.
{
"target": {
"_events": {
"close": [null, null]
},
"_eventsCount": 3,
"readyState": 2,
"protocol": "",
"_binaryType": "nodebuffer",
"_closeFrameReceived": false,
"_closeFrameSent": false,
"_closeMessage": "",
"_closeTimer": null,
"_closeCode": 1002,
"_extensions": {},
"_receiver": {
"_writableState": {
"objectMode": false,
"highWaterMark": 16384,
"finalCalled": false,
"needDrain": false,
"ending": false,
"ended": false,
"finished": false,
"destroyed": false,
"decodeStrings": true,
"defaultEncoding": "utf8",
"length": 0,
"writing": false,
"corked": 0,
"sync": true,
"bufferProcessing": false,
"writecb": null,
"writelen": 0,
"bufferedRequest": null,
"lastBufferedRequest": null,
"pendingcb": 0,
"prefinished": false,
"errorEmitted": true,
"emitClose": true,
"autoDestroy": false,
"bufferedRequestCount": 0,
"corkedRequestsFree": {
"next": null,
"entry": null
}
},
"writable": true,
"_events": {},
"_eventsCount": 6,
"_binaryType": "nodebuffer",
"_extensions": {},
"_maxPayload": 104857600,
"_bufferedBytes": 1440,
"_buffers": [{
"type": "Buffer",
"data": [some_data]
}],
"_compressed": false,
"_payloadLength": 126,
"_mask": {
"type": "Buffer",
"data": [40, 116, 54, 115]
},
"_fragmented": 0,
"_masked": true,
"_fin": true,
"_opcode": 10,
"_totalPayloadLength": 0,
"_messageLength": 0,
"_fragments": [],
"_state": 0,
"_loop": false
},
"_sender": {

If anybody know what migtht cause this error would be nice as well.

@lpinca
Copy link
Member

lpinca commented Nov 19, 2019

Hi,
you get this error when the "payload length" of a control frame (ping, pong, or close) has a value bigger than 125. All control frames must have a payload length of 125 bytes or less.

See https://tools.ietf.org/html/rfc6455#section-5.2 and https://tools.ietf.org/html/rfc6455#section-5.5 for more info.

@lpinca
Copy link
Member

lpinca commented Nov 19, 2019

You can reproduce with the following code:

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 }, function() {
  const ws = new WebSocket('ws://localhost:8080');

  ws.on('open', function() {
    ws._socket.write(Buffer.from([0x89, 0xfe]));
  });
});

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

@lpinca lpinca closed this as completed Nov 19, 2019
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