From 09637948e71e88c66b9e40389b4a46c60659f6e3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 28 Oct 2023 21:57:59 -0400 Subject: [PATCH] fix: wrap sync in try/catch and unlock mutex in a finally --- src/baseClient.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/baseClient.ts b/src/baseClient.ts index 8d22b0c..39fea04 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -170,18 +170,22 @@ export default abstract class BaseClient extends EventEmitter { protected async _sync() { await this.syncMutex.acquire(); - const currentPeriod = this.getCurrentPeriod(); - if (currentPeriod > this._latestPeriod) { - if (!this.booted) { - this.latestCommittee = await this.syncFromGenesis(); - } else { - this.latestCommittee = await this.syncFromLastUpdate(); + try { + const currentPeriod = this.getCurrentPeriod(); + if (currentPeriod > this._latestPeriod) { + if (!this.booted) { + this.latestCommittee = await this.syncFromGenesis(); + } else { + this.latestCommittee = await this.syncFromLastUpdate(); + } + this._latestPeriod = currentPeriod; + this.emit("synced"); } - this._latestPeriod = currentPeriod; - this.emit("synced"); + } catch (e) { + console.log(e); + } finally { + this.syncMutex.release(); } - - this.syncMutex.release(); } protected async subscribe(callback?: (ei: ExecutionInfo) => void) {