1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix exception upon failure to get next nonce (#9598)

An attempt to safely release the `nonceLock` upon failure has instead
made failure worse by masking it with a new error. If the call to get
the `nonceLock` throws an exception, then the `finally` block here
would attempt to call `releaseLock` on the `nonceLock` variable, which
is guaranteed to be `undefined` if the previous call failed. The
attempt to call a method on `undefined` throws another error, masking
the original error.

It is safer to obtain the `nonceLock` and release it without using any
`try` or `finally` block. The `nonceLock` is synchronously released
immediately after it is obtained, and any errors bubble up correctly
without being masked. There is no case where the lock is left
unreleased.
This commit is contained in:
Mark Stacey 2020-10-14 13:34:08 -02:30 committed by GitHub
parent e53f970458
commit 360d8ded1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1864,12 +1864,8 @@ export default class MetamaskController extends EventEmitter {
* @returns {Promise<number>}
*/
async getNextNonce (address) {
let nonceLock
try {
nonceLock = await this.txController.nonceTracker.getNonceLock(address)
} finally {
nonceLock.releaseLock()
}
const nonceLock = await this.txController.nonceTracker.getNonceLock(address)
nonceLock.releaseLock()
return nonceLock.nextNonce
}