From 22855def275e7b9187bcd2148e98573051edfc98 Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Thu, 7 Mar 2019 10:58:32 -0800 Subject: [PATCH] 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. --- runtime/src/accounts.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 5eb3857ae3..3342a18187 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -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);