-
Notifications
You must be signed in to change notification settings - Fork 109
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
WebSocket closed error #65
Comments
Hi have the same problem, will be nice if you can change this |
See #25 for some other suggestions on how to trap errors. If the socket isn't open then it should return an error allowing the application to re-open the socket. |
NOTE: Currently testing on 3.1.0-ws, had to make a couple of additional changes, will post once fully tested. I've added extra code to detect and report this issue back and terminate the app allowing the process manager to re-start. pm2 logs
The events loop catches the socket closure and aborts the app, the process manager (pm2) catches this and re-starts:
Here you can see the event listener has been restarted twice because the connection was closed. core event handler
ewelink-api/mixins/websocket/openWebSocketMixin.js
This code now catches errors and passes them up to the calling code to deal with. The way I've delt with it is to just restart my event monitor, very simple and reliable. When a ping is sent every 2min the socket stays open.
If I comment out sending the ping the code catches the socket timeout:
|
Any update on this issue? |
Hi |
Hi. The ewelink-api/src/mixins/openWebSocket.js in this repository: ewelink-api/src/mixins/openWebSocket.js Lines 38 to 40 in 5a07f6b
I changed to get credentials and try to restart the WebSocket:
This way it closes the connection but doesn't close the process. It tries to connect again. I'm still learning about JavaScript and I know that this code is very primitive, however, it solved my connection problem. |
When the hearbeat interval function runs it does not check if the websocket is open and that often creates error like this one:
(node:914) UnhandledPromiseRejectionWarning: Error: Can't send data because WebSocket is not opened. at exports.throwIf (/root/nodejs/ewelink-sserver/node_modules/websocket-as-promised/dist/index.js:3470:11) at WebSocketAsPromised.send (/root/nodejs/ewelink-sserver/node_modules/websocket-as-promised/dist/index.js:554:7) at Timeout._onTimeout (/root/nodejs/ewelink-sserver/node_modules/ewelink-api/mixins/websocket/openWebSocketMixin.js:38:17) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7)
Please add the check "if (wsp.isOpened)" to the interval function (line 37 in openWebSocketMixin):
The text was updated successfully, but these errors were encountered: