fix: wrap sync in try/catch and unlock mutex in a finally
This commit is contained in:
parent
772d7eb21e
commit
09637948e7
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue