Skip to content

Commit 22baa68

Browse files
committed
fix: use mutex pattern for deserialize
1 parent a6aef0d commit 22baa68

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/keyring-eth-simple/src/simple-keyring-v2.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ export class SimpleKeyringV2
192192
}
193193

194194
async deserialize(state: Json): Promise<void> {
195-
// Clear the registry when deserializing
196-
this.registry.clear();
195+
await this.#lock.runExclusive(async () => {
196+
// Clear the registry when deserializing
197+
this.registry.clear();
197198

198-
// Deserialize the legacy keyring
199-
await this.inner.deserialize(state as string[]);
199+
// Deserialize the legacy keyring
200+
await this.inner.deserialize(state as string[]);
200201

201-
// Rebuild the registry by populating it with all accounts
202-
// We call getAccounts() which will repopulate the registry as a side effect
203-
await this.getAccounts();
202+
// Rebuild the registry by populating it with all accounts
203+
// We call getAccounts() which will repopulate the registry as a side effect
204+
await this.getAccounts();
205+
});
204206
}
205207

206208
async createAccounts(

0 commit comments

Comments
 (0)