home-assistant / home-assistant-js-websocket

:aerial_tramway: JavaScript websocket client for Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unhandled promise rejection after a reconnection and during resubscribing to events

zachowj opened this issue · comments

commented

Getting an unhandled promise rejection when it's resubscribing to events after a reconnect and the socket drops the connection.

await this.sendMessagePromise(
messages.subscribeEvents(eventType),
commandId
);

Getting two different errors seems to be a race condition on which one gets thrown.

First One:

This is referencing the above SendMessagePromise

UnhandledPromiseRejectionWarning: Error: WebSocket is not open: readyState 2 (CLOSING)
    at WebSocket.send (/opt/node_modules/node-red-contrib-home-assistant-websocket/node_modules/ws/lib/websocket.js:314:19)
    at e.sendMessage (/opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:3458)
    at /opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:3630
    at new Promise (<anonymous>)
    at e.sendMessagePromise (/opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:3546)
    at p (/opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:8102)
    at w (/opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:8802)
    at /opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:7847
    at /opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:1440
    at Object.next (/opt/node_modules/home-assistant-js-websocket/dist/haws.umd.js:1:1545)

Second One:

// Reject in-flight requests
Object.keys(this.commands).forEach(id => {
const { reject } = this.commands[id];
if (reject) {
reject(messages.error(ERR_CONNECTION_LOST, "Connection lost"));
}
});

Context:

Using node-red-contrib-home-assistant-websocket within hass.io and the addon-node-red. Everything works fine with the connection until you reboot hass.io and the addon is trying to reconnect. While trying to reconnect to Home Assistant it connects and disconnects from the hass.io proxy several times that's when the errors are getting thrown.

commented

Duplicate because github was having issues #59