Websocket Server in Node.js return RSV1 error when accessing from the phone APP

Viewed 2909

In Node.js, I have implemented a WebSocket server which is used by a smartphone app. In some cases I got this kind of error (Invalid WebSocket frame: RSV1 must be clear):

enter image description here

This kind of application is running on many different servers across the world, but have the problem only with one instance. The app crashes randomly when using the communication between smartphones (Android or IOS) but it did not crash if I try to send messages over WebSocket using Java.

Looking at the doc of WebSocket specification have found that: enter image description here

Currently, I can't find what could be wrong. Do you think it could be some "network set-up issue"?

The libraries used for WebSocket in Node.js is ws 6.2.1.

The service is running inside a docker using alpine:8 image. As I told I have a problem only in one environment in all other environments everything works fine. Any idea what else to check?

2 Answers

Well in my case i was sending an object, when i JSON.stringify() it , it started working

For my case I put in return and it solves my issue:

Before:

if (pathname === "/foo/1") {
  wss.handleUpgrade(request, socket, head, function done(ws) {
    wss.emit("connection", ws, request);
  });
}

After:

if (pathname === "/foo/1") {
  wss.handleUpgrade(request, socket, head, function done(ws) {
    wss.emit("connection", ws, request);
  });
  return;
}
Related