1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

metamask - ensure all nonce locks are released

This commit is contained in:
kumavis 2018-06-12 11:51:35 -07:00
parent 8f93e34175
commit 177cc3f280
4 changed files with 18 additions and 17 deletions

View File

@ -264,7 +264,12 @@ class TransactionController extends EventEmitter {
// must set transaction to submitted/failed before releasing lock // must set transaction to submitted/failed before releasing lock
nonceLock.releaseLock() nonceLock.releaseLock()
} catch (err) { } catch (err) {
// this is try-catch wrapped so that we can guarantee that the nonceLock is released
try {
this.txStateManager.setTxStatusFailed(txId, err) this.txStateManager.setTxStatusFailed(txId, err)
} catch (err) {
console.error(err)
}
// must set transaction to submitted/failed before releasing lock // must set transaction to submitted/failed before releasing lock
if (nonceLock) nonceLock.releaseLock() if (nonceLock) nonceLock.releaseLock()
// continue with error chain // continue with error chain

View File

@ -91,8 +91,8 @@ class NonceTracker {
async _globalMutexFree () { async _globalMutexFree () {
const globalMutex = this._lookupMutex('global') const globalMutex = this._lookupMutex('global')
const release = await globalMutex.acquire() const releaseLock = await globalMutex.acquire()
release() releaseLock()
} }
async _takeMutex (lockId) { async _takeMutex (lockId) {

View File

@ -196,14 +196,14 @@ class PendingTransactionTracker extends EventEmitter {
async _checkPendingTxs () { async _checkPendingTxs () {
const signedTxList = this.getPendingTransactions() const signedTxList = this.getPendingTransactions()
// in order to keep the nonceTracker accurate we block it while updating pending transactions // in order to keep the nonceTracker accurate we block it while updating pending transactions
const nonceGlobalLock = await this.nonceTracker.getGlobalLock() const { releaseLock } = await this.nonceTracker.getGlobalLock()
try { try {
await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta))) await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta)))
} catch (err) { } catch (err) {
log.error('PendingTransactionWatcher - Error updating pending transactions') log.error('PendingTransactionWatcher - Error updating pending transactions')
log.error(err) log.error(err)
} }
nonceGlobalLock.releaseLock() releaseLock()
} }
/** /**

View File

@ -436,28 +436,24 @@ module.exports = class MetamaskController extends EventEmitter {
* @returns {Object} vault * @returns {Object} vault
*/ */
async createNewVaultAndKeychain (password) { async createNewVaultAndKeychain (password) {
const release = await this.createVaultMutex.acquire() const releaseLock = await this.createVaultMutex.acquire()
let vault
try { try {
let vault
const accounts = await this.keyringController.getAccounts() const accounts = await this.keyringController.getAccounts()
if (accounts.length > 0) { if (accounts.length > 0) {
vault = await this.keyringController.fullUpdate() vault = await this.keyringController.fullUpdate()
} else { } else {
vault = await this.keyringController.createNewVaultAndKeychain(password) vault = await this.keyringController.createNewVaultAndKeychain(password)
const accounts = await this.keyringController.getAccounts() const accounts = await this.keyringController.getAccounts()
this.preferencesController.setAddresses(accounts) this.preferencesController.setAddresses(accounts)
this.selectFirstIdentity() this.selectFirstIdentity()
} }
release() releaseLock()
return vault
} catch (err) { } catch (err) {
release() releaseLock()
throw err throw err
} }
return vault
} }
/** /**
@ -466,7 +462,7 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {} seed * @param {} seed
*/ */
async createNewVaultAndRestore (password, seed) { async createNewVaultAndRestore (password, seed) {
const release = await this.createVaultMutex.acquire() const releaseLock = await this.createVaultMutex.acquire()
try { try {
// clear known identities // clear known identities
this.preferencesController.setAddresses([]) this.preferencesController.setAddresses([])
@ -476,10 +472,10 @@ module.exports = class MetamaskController extends EventEmitter {
const accounts = await this.keyringController.getAccounts() const accounts = await this.keyringController.getAccounts()
this.preferencesController.setAddresses(accounts) this.preferencesController.setAddresses(accounts)
this.selectFirstIdentity() this.selectFirstIdentity()
release() releaseLock()
return vault return vault
} catch (err) { } catch (err) {
release() releaseLock()
throw err throw err
} }
} }