Fix race condition in store.

Multiple threads can enter the read lock and
all store the new empty set to account_maps.
Check again after taking write lock to make sure
only one thread actually inserts the new entry.
This commit is contained in:
Stephen Akridge 2019-03-07 10:58:32 -08:00 committed by sakridge
parent 0be59cad4e
commit 22855def27
1 changed files with 3 additions and 1 deletions

View File

@ -513,7 +513,9 @@ impl AccountsDB {
.contains_key(&pubkey)
{
let mut waccount_maps = self.account_index.account_maps.write().unwrap();
waccount_maps.insert(*pubkey, RwLock::new(HashMap::new()));
if !waccount_maps.contains_key(&pubkey) {
waccount_maps.insert(*pubkey, RwLock::new(HashMap::new()));
}
}
}
self.store_account(fork, pubkey, account);