Skip to content

Commit

Permalink
account-manager: stop after 100 attempts to generate account id
Browse files Browse the repository at this point in the history
  • Loading branch information
fredriklindberg committed Apr 29, 2021
1 parent 9d0ca96 commit 630ed86
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/account/account-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ class AccountManager {

async create() {
let accountId;
let maxTries = 100;
do {
accountId = Account.generateId();
const created = await this._db.set(accountId, {}, {NX: true});
if (!created) {
accountId = undefined;
}
} while (accountId === undefined)
} while (accountId === undefined && maxTries-- > 0);

if (!accountId) {
return undefined;
}

return new Account(accountId);
}
Expand Down

0 comments on commit 630ed86

Please sign in to comment.