neo
neo copied to clipboard
A concurrency problem in `SQLiteWallet` because of across execution
Describe the bug
In SQLiteWallet, it uses two lock to avoid concurrency problems:
-
lock (accounts)to protect theaccountsstructure; -
lock (db_lock)to protect theWalletDataContext;
Because there are two locks, and there not locked at the same time. This method may lead to some problems in some cases, for example:
- Cross-execution of the
CreateAccountand theDeleteAccount: These two methods use same lock step:
lock (accounts) {
// step 1;
}
lock (db_lock) {
// step 2;
}
It may lead to unconsistency state if a thread executed AddAccount step 1 and switched out, then another thread executed DeleteAccount step 1 and step 2, then thread-1 executes AddAccount step 2.
- Cross-execution of diffirent
CreateAccounts: Similar execution process.