From d030cad3bbc3256a524c155bfd4a0e2e41e896a7 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 14 Mar 2023 13:39:34 +0100 Subject: [PATCH] fix: catch errors in `pollBackgroundRSSITimer` --- packages/zwave-js/src/lib/driver/Driver.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 89a74f7ed21a..22e2b0d1f745 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -5178,11 +5178,16 @@ ${handlers.length} left`, // and up to 30s if we recently queried the RSSI 30_000 - (Date.now() - this.lastBackgroundRSSITimestamp), ); - this.pollBackgroundRSSITimer = setTimeout(() => { + this.pollBackgroundRSSITimer = setTimeout(async () => { + // Due to the timeout, the driver might have been destroyed in the meantime + if (!this.ready) return; + this.lastBackgroundRSSITimestamp = Date.now(); - void this.controller.getBackgroundRSSI().catch(() => { + try { + await this.controller.getBackgroundRSSI(); + } catch { // ignore errors - }); + } }, timeout).unref(); } else { clearTimeout(this.pollBackgroundRSSITimer);