You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The 5-second debounce in subscribeServices is causing an UnhandledPromiseRejection. When the Home Assistant connection is terminated during the debounce window, sendMessage is called while the connection is already in a disconnected state, leading to the rejection.
Steps to Reproduce:
Run the provided example script.
Start Home Assistant.
Wait five seconds after disconnect to observe the issue.
This can be easily reproduced by starting the script before Home Assistant is fully up, allowing the service updates to trigger the debounce.
Example Code:
import{createConnection,subscribeServices,createLongLivedTokenAuth,}from"./dist/index.js";(async()=>{constauth=createLongLivedTokenAuth("http://localhost:8123","<TOKEN>",);letcounter=0;constconnection=awaitcreateConnection({ auth,setupRetry: -1});subscribeServices(connection,()=>{console.log("Services updated",counter++);// wait for 2 updates so debounce fetches services// simulate connection close from client// this can be removed and manually terminate Home Assistant before the debounce fetches servicesif(counter>2&&connection.connected){console.log("Closing connection");connection.close();console.log("wait for it...");}});})();
Console Output:
Services updated 0
Services updated 1
Services updated 2
Closing connection
waitfor it...
node:internal/process/promises:389
new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async functionwithout a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "3".
at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
at processPromiseRejections (node:internal/process/promises:470:17)
at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Stack Trace: line numbers are 2 off due to console.logs i had in the code
sendMessage: { type: 'get_services' } connected: false
Error
at Connection.sendMessage (file:///home/jason/projects/home-assistant-js-websocket/dist/connection.js:244:21)
at file:///home/jason/projects/home-assistant-js-websocket/dist/connection.js:283:18
at new Promise (<anonymous>)
at Connection.sendMessagePromise (file:///home/jason/projects/home-assistant-js-websocket/dist/connection.js:266:16)
at getServices (file:///home/jason/projects/home-assistant-js-websocket/dist/commands.js:3:55)
at fetchServices (file:///home/jason/projects/home-assistant-js-websocket/dist/services.js:31:33)
at file:///home/jason/projects/home-assistant-js-websocket/dist/services.js:30:58
at Timeout.later [as _onTimeout] (file:///home/jason/projects/home-assistant-js-websocket/dist/util.js:27:22)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
The text was updated successfully, but these errors were encountered:
zachowj
changed the title
Debounce in service collection triggers UnhandledPromiseRejection when connection is terminated in window
Debounce in service collection throw UnhandledPromiseRejection when connection is terminated in window
Oct 3, 2024
zachowj
changed the title
Debounce in service collection throw UnhandledPromiseRejection when connection is terminated in window
Debounce in service collection throws UnhandledPromiseRejection when connection is terminated in window
Oct 3, 2024
The 5-second debounce in
subscribeServices
is causing anUnhandledPromiseRejection
. When the Home Assistant connection is terminated during the debounce window,sendMessage
is called while the connection is already in a disconnected state, leading to the rejection.Steps to Reproduce:
This can be easily reproduced by starting the script before Home Assistant is fully up, allowing the service updates to trigger the debounce.
Example Code:
Console Output:
Stack Trace: line numbers are 2 off due to console.logs i had in the code
The text was updated successfully, but these errors were encountered: