Skip to content

Commit

Permalink
wallet-ext: keyring fix locking and reviving race condition (#6848)
Browse files Browse the repository at this point in the history
* when it's time to lock the keyring due to inactivity there is a race condition between reviving from session storage and locking because of the alarm. (Keyring is trying to revive since bg service wakes up to respond to the alarm and before completing we lock it)
* this fixes it by waiting reviving to complete before locking
* this only happens if bg service was inactive before the alarm was triggered
  • Loading branch information
pchrysochoidis authored Dec 16, 2022
1 parent 63c418f commit 64de411
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/wallet/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Keyring.on('lockedStatusUpdate', (isLocked: boolean) => {

Browser.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === LOCK_ALARM_NAME) {
Keyring.lock();
Keyring.reviveDone.finally(() => Keyring.lock());
}
});

Expand Down
6 changes: 3 additions & 3 deletions apps/wallet/src/background/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Keyring {
#locked = true;
#keypair: Keypair | null = null;
#vault: VaultStorage;
#reviveDone: Promise<void>;
public readonly reviveDone: Promise<void>;

constructor() {
this.#vault = new VaultStorage();
this.#reviveDone = this.revive().catch((e) => {
this.reviveDone = this.revive().catch((e) => {
// if for some reason decrypting the vault fails or anything else catch
// the error to allow the user to login using the password
});
Expand Down Expand Up @@ -134,7 +134,7 @@ class Keyring {
} else if (isKeyringPayload(payload, 'walletStatusUpdate')) {
// wait to avoid ui showing locked and then unlocked screen
// ui waits until it receives this status to render
await this.#reviveDone;
await this.reviveDone;
uiConnection.send(
createMessage<KeyringPayload<'walletStatusUpdate'>>(
{
Expand Down

0 comments on commit 64de411

Please sign in to comment.