It would appear the err object is not an error object. That’s why it’s difficult to pin-down, nothing is shown. It’s an HaWebsocket object.
Still no clue as to why the connection is closing.
The best I can figure out, at some point a reconnect-error
is triggered by the polling tick. This then starts a down-stream of errors, not captured anywhere. The best I can see is this might be a home-assistant-js-websocket
bug – failing to properly pass the resulting error? However, I can’t trace that as it’s all uncompiled .ts
libraries on the filesystem.
root@a0d7b954-nodered:/var/run/s6/services$ ls -l /opt/node_modules/home-assistant-js-websocket/lib/connection.ts
ls: /opt/node_modules/home-assistant-js-websocket/lib/connection.ts: No such file or directory
root@a0d7b954-nodered:/var/run/s6/services$ ls -l /opt/node_modules/home-assistant-js-websocket/
total 40
-rw-r--r-- 1 root root 10480 Oct 26 1985 LICENSE.md
-rw-r--r-- 1 root root 17875 Oct 26 1985 README.md
drwxr-xr-x 1 root root 4096 Jan 1 13:05 dist
-rw-r--r-- 1 root root 2365 Dec 17 05:20 package.json
root@a0d7b954-nodered:/var/run/s6/services$ ls -l /opt/node_modules/home-assistant-js-websocket/dist
total 308
-rw-r--r-- 1 root root 1177 Oct 26 1985 auth.d.ts
-rw-r--r-- 1 root root 832 Oct 26 1985 collection.d.ts
-rw-r--r-- 1 root root 597 Oct 26 1985 commands.d.ts
-rw-r--r-- 1 root root 217 Oct 26 1985 config.d.ts
-rw-r--r-- 1 root root 2409 Oct 26 1985 connection.d.ts
-rw-r--r-- 1 root root 330 Oct 26 1985 entities.d.ts
-rw-r--r-- 1 root root 240 Oct 26 1985 errors.d.ts
-rw-r--r-- 1 root root 12025 Oct 26 1985 haws.es.js
-rw-r--r-- 1 root root 70597 Oct 26 1985 haws.es.js.map
-rw-r--r-- 1 root root 12076 Oct 26 1985 haws.js
-rw-r--r-- 1 root root 70307 Oct 26 1985 haws.js.map
-rw-r--r-- 1 root root 12120 Oct 26 1985 haws.umd.js
-rw-r--r-- 1 root root 70301 Oct 26 1985 haws.umd.js.map
-rw-r--r-- 1 root root 446 Oct 26 1985 index.d.ts
-rw-r--r-- 1 root root 1184 Oct 26 1985 messages.d.ts
-rw-r--r-- 1 root root 223 Oct 26 1985 services.d.ts
-rw-r--r-- 1 root root 133 Oct 26 1985 socket.d.ts
-rw-r--r-- 1 root root 628 Oct 26 1985 store.d.ts
-rw-r--r-- 1 root root 2569 Oct 26 1985 types.d.ts
-rw-r--r-- 1 root root 64 Oct 26 1985 util.d.ts
Here’s a full trace of the onClientError() event trigger:
1 Jan 13:23:10 - [debug] [server:Home Assistant] config server event listener connecting
Trace: o {
options:
{ setupRetry: 0,
createSocket: [Function: createSocket],
self:
HaWebsocket {
_events: [Object],
_eventsCount: 13,
_maxListeners: 0,
config: [Object],
connectionState: 0,
states: [Object],
services: [Object],
statesLoaded: false,
client: [Circular],
subscribedEvents: [Set],
unsubCallback: [Object],
integrationVersion: 0,
servicesLoaded: false } },
commandId: 11,
commands:
Map {
2 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
3 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
5 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
6 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
8 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
9 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] },
11 => { resolve: [Function],
reject: [Function],
callback: [Function],
subscribe: [Function: subscribe],
unsubscribe: [Function: unsubscribe] } },
eventListeners:
Map {
'ready' => [ [Function: bound onClientOpen],
[Function: u],
[Function: u],
[Function: u] ],
'disconnected' => [ [Function: bound onClientClose] ],
'reconnect-error' => [ [Function: bound onClientError] ] },
closeRequested: false,
socket:
WebSocket {
_events:
[Object: null prototype] { message: [Function], close: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
readyState: 3,
protocol: '',
_binaryType: 'nodebuffer',
_closeFrameReceived: true,
_closeFrameSent: true,
_closeMessage: '',
_closeTimer:
Timeout {
_called: false,
_idleTimeout: -1,
_idlePrev: null,
_idleNext: null,
_idleStart: 74563,
_onTimeout: null,
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(unrefed)]: false,
[Symbol(asyncId)]: 1783,
[Symbol(triggerId)]: 1358 },
_closeCode: 1000,
_extensions: { 'permessage-deflate': [PerMessageDeflate] },
_receiver:
Receiver {
_writableState: [WritableState],
writable: false,
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_binaryType: 'nodebuffer',
_extensions: [Object],
_maxPayload: 104857600,
_bufferedBytes: 0,
_buffers: [],
_compressed: true,
_payloadLength: 2,
_mask: undefined,
_fragmented: 0,
_masked: false,
_fin: true,
_opcode: 8,
_totalPayloadLength: 0,
_messageLength: 0,
_fragments: [],
_state: 0,
_loop: false,
[Symbol(websocket)]: [Circular] },
_sender:
Sender {
_extensions: [Object],
_socket: [Socket],
_firstFragment: true,
_compress: false,
_bufferedBytes: 0,
_deflating: false,
_queue: [] },
_socket:
Socket {
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'hassio',
_readableState: [ReadableState],
readable: false,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
parser: null,
_httpMessage: null,
timeout: 0,
write: [Function: writeAfterFIN],
[Symbol(asyncId)]: 1358,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 40143,
[Symbol(kBytesWritten)]: 1010,
[Symbol(websocket)]: undefined },
_bufferedAmount: 0,
_isServer: false,
_redirects: 0,
url: 'ws://hassio/homeassistant/websocket',
_req: null },
_ent:
{ state: [Getter],
refresh: [Function: c],
subscribe: [Function: subscribe] },
_srv:
{ state: [Getter],
refresh: [Function: c],
subscribe: [Function: subscribe] },
_cnf:
{ state: [Getter],
refresh: [Function: c],
subscribe: [Function: subscribe] } }
at HaWebsocket.callback [as onClientError] (/opt/node_modules/node-red-contrib-home-assistant-websocket/lib/ha-websocket.js:266:10)
at forEach (/opt/node_modules/home-assistant-js-websocket/lib/connection.ts:153:7)
at Array.forEach (<anonymous>)
at o.fireEvent (/opt/node_modules/home-assistant-js-websocket/lib/connection.ts:152:48)
at /opt/node_modules/home-assistant-js-websocket/lib/connection.ts:327:18
at process._tickCallback (internal/process/next_tick.js:68:7)
This is a dump of the result of this addition:
@node_modules/node-red-contrib-home-assistant-websocket/lib/ha-websocket.js:266
onClientError(data) {
console.trace(data);
this.closeClient(
data,
'events connection error, cleaning up connection'
);
}
The websocket object has a closeCode 1000, and according to the docs: this is a perfectly normal closure – https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
So, something else is broken.