WebThingsIO / gateway

WebThings Gateway
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 333 forks source link

`WebSocket sendMessage failed` when adding a thing to a group #3102

Open benfrancis opened 10 months ago

benfrancis commented 10 months ago

STR:

  1. Create a group
  2. Add a thing to a group

Expected:

  1. Thing is added to the group with no errors on the console

Actual:

  1. See an error on the console:

ERROR : WebSocket sendMessage failed: Error: WebSocket is not open: readyState 3 (CLOSED)

Similar bugs that may or may not be related:

benfrancis commented 10 months ago

It appears this error is only emitted when the server tries to send a message to a client which has not properly closed its WebSocket connection. Messages are successfully sent to open WebSockets.

The ReopeningWebSocket class on the client side appears to call WebSocket.close() on the beforeunload event, and groups_controller is meant to terminate WebSockets which haven't received a ping response in 30 seconds.

It's a bit tricky to test whether this is all working correctly, but if it is then I'm not sure there's much more we can do to prevent these errors.