neo icon indicating copy to clipboard operation
neo copied to clipboard

A concurrency problem in `SQLiteWallet` because of across execution

Open nan01ab opened this issue 1 year ago • 0 comments

Describe the bug In SQLiteWallet, it uses two lock to avoid concurrency problems:

  • lock (accounts) to protect the accounts structure;
  • lock (db_lock) to protect the WalletDataContext;

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:

  1. Cross-execution of the CreateAccount and the DeleteAccount: 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.

  1. Cross-execution of diffirent CreateAccounts: Similar execution process.

nan01ab avatar Oct 13 '24 14:10 nan01ab