websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.7k stars 2.42k forks source link

Websocket disconnects with 1006 error, without a reason #1520

Closed Esqarrouth closed 5 years ago

Esqarrouth commented 5 years ago

Description

I'm logging disconnects in my web game. It seems 75% of the sessions are getting disconnected with the code 1001 (normal) and 25% are getting disconnected with the code 1006 (error). https://tools.ietf.org/html/rfc6455

Sometimes on the error reason I see this text:

CloudFlare WebSocket Proxy restarting

But he majority of 1006 disconnects don't give any reason at all. The players just disconnect with no reason at all. This usually happens at 5-30 minutes mark while the player is actively playing the game.

The setup I'm has these:

My question is:

  1. How can I debug this problem better?
  2. What are common cases which might be causing this problem?

Reproducible in:

Also posted in: https://stackoverflow.com/questions/54909597/websocket-disconnects-with-1006-error-without-a-reason

lpinca commented 5 years ago
  1. How can I debug this problem better?

There is not much you can do about it because it's not an issue. It's a condition you have to deal with.

  1. What are common cases which might be causing this problem?

A close frame is not received, likely because it was not sent.

lpinca commented 5 years ago

Btw, update at least to https://github.com/websockets/ws/releases/tag/6.1.3. The bug fixed there is relevant and important.

lpinca commented 5 years ago

Nvm, the 3.x release line should not be affected by that but it doesn't harm anyway to update, if you can.

Esqarrouth commented 5 years ago

I'm tracking the disconnections used ws 3.3.1 until 3 March then updated ws to 6.1.4. I am adding the charts.

Conclusion:

21

23
lpinca commented 5 years ago

I hope this is the expected behaviour?

Yes, 1005 is a close frame with an empty payload.

Esqarrouth commented 5 years ago
  1. How can I debug this problem better?

There is not much you can do about it because it's not an issue. It's a condition you have to deal with.

  1. You mean it is not an issue with ws, right?
  2. What do you mean there is not much you can do about it?
  3. What do you mean it's a condition you have to deal with? If it is common, how do you or other people generally deal with this issue?
  1. What are common cases which might be causing this problem?

A close frame is not received, likely because it was not sent.

  1. Do you mean that socket server didn't send the close frame to client?
lpinca commented 5 years ago
  1. You mean it is not an issue with ws, right?

Yes, I'm not aware of ws dropping close frames.

  1. What do you mean there is not much you can do about it?

It's outside of your control. You can't force the client to send a close frame. If this is coming from a browser try to call ws.close() before the page unload and see if it makes any difference.

  1. What do you mean it's a condition you have to deal with? If it is common, how do you or other people generally deal with this issue?

Treat it for what it is. An "abnormal" closure.

  1. Do you mean that socket server didn't send the close frame to client?

The client.