fix: wrap sync in try/catch and unlock mutex in a finally

This commit is contained in:
Derrick Hammer 2023-10-28 21:57:59 -04:00
parent 772d7eb21e
commit 09637948e7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 10 deletions

View File

@ -170,18 +170,22 @@ export default abstract class BaseClient extends EventEmitter {
protected async _sync() { protected async _sync() {
await this.syncMutex.acquire(); await this.syncMutex.acquire();
const currentPeriod = this.getCurrentPeriod(); try {
if (currentPeriod > this._latestPeriod) { const currentPeriod = this.getCurrentPeriod();
if (!this.booted) { if (currentPeriod > this._latestPeriod) {
this.latestCommittee = await this.syncFromGenesis(); if (!this.booted) {
} else { this.latestCommittee = await this.syncFromGenesis();
this.latestCommittee = await this.syncFromLastUpdate(); } else {
this.latestCommittee = await this.syncFromLastUpdate();
}
this._latestPeriod = currentPeriod;
this.emit("synced");
} }
this._latestPeriod = currentPeriod; } catch (e) {
this.emit("synced"); console.log(e);
} finally {
this.syncMutex.release();
} }
this.syncMutex.release();
} }
protected async subscribe(callback?: (ei: ExecutionInfo) => void) { protected async subscribe(callback?: (ei: ExecutionInfo) => void) {