mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
metamask - ensure all nonce locks are released
This commit is contained in:
parent
8f93e34175
commit
177cc3f280
@ -264,7 +264,12 @@ class TransactionController extends EventEmitter {
|
||||
// must set transaction to submitted/failed before releasing lock
|
||||
nonceLock.releaseLock()
|
||||
} catch (err) {
|
||||
this.txStateManager.setTxStatusFailed(txId, err)
|
||||
// this is try-catch wrapped so that we can guarantee that the nonceLock is released
|
||||
try {
|
||||
this.txStateManager.setTxStatusFailed(txId, err)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
// must set transaction to submitted/failed before releasing lock
|
||||
if (nonceLock) nonceLock.releaseLock()
|
||||
// continue with error chain
|
||||
|
@ -91,8 +91,8 @@ class NonceTracker {
|
||||
|
||||
async _globalMutexFree () {
|
||||
const globalMutex = this._lookupMutex('global')
|
||||
const release = await globalMutex.acquire()
|
||||
release()
|
||||
const releaseLock = await globalMutex.acquire()
|
||||
releaseLock()
|
||||
}
|
||||
|
||||
async _takeMutex (lockId) {
|
||||
|
@ -196,14 +196,14 @@ class PendingTransactionTracker extends EventEmitter {
|
||||
async _checkPendingTxs () {
|
||||
const signedTxList = this.getPendingTransactions()
|
||||
// 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 {
|
||||
await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta)))
|
||||
} catch (err) {
|
||||
log.error('PendingTransactionWatcher - Error updating pending transactions')
|
||||
log.error(err)
|
||||
}
|
||||
nonceGlobalLock.releaseLock()
|
||||
releaseLock()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -436,28 +436,24 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
* @returns {Object} vault
|
||||
*/
|
||||
async createNewVaultAndKeychain (password) {
|
||||
const release = await this.createVaultMutex.acquire()
|
||||
let vault
|
||||
|
||||
const releaseLock = await this.createVaultMutex.acquire()
|
||||
try {
|
||||
let vault
|
||||
const accounts = await this.keyringController.getAccounts()
|
||||
|
||||
if (accounts.length > 0) {
|
||||
vault = await this.keyringController.fullUpdate()
|
||||
|
||||
} else {
|
||||
vault = await this.keyringController.createNewVaultAndKeychain(password)
|
||||
const accounts = await this.keyringController.getAccounts()
|
||||
this.preferencesController.setAddresses(accounts)
|
||||
this.selectFirstIdentity()
|
||||
}
|
||||
release()
|
||||
releaseLock()
|
||||
return vault
|
||||
} catch (err) {
|
||||
release()
|
||||
releaseLock()
|
||||
throw err
|
||||
}
|
||||
|
||||
return vault
|
||||
}
|
||||
|
||||
/**
|
||||
@ -466,7 +462,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
* @param {} seed
|
||||
*/
|
||||
async createNewVaultAndRestore (password, seed) {
|
||||
const release = await this.createVaultMutex.acquire()
|
||||
const releaseLock = await this.createVaultMutex.acquire()
|
||||
try {
|
||||
// clear known identities
|
||||
this.preferencesController.setAddresses([])
|
||||
@ -476,10 +472,10 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
const accounts = await this.keyringController.getAccounts()
|
||||
this.preferencesController.setAddresses(accounts)
|
||||
this.selectFirstIdentity()
|
||||
release()
|
||||
releaseLock()
|
||||
return vault
|
||||
} catch (err) {
|
||||
release()
|
||||
releaseLock()
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user