diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-08 07:36:06 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-08 07:36:06 +0800 |
commit | d6a7332993cf32960ef94947341cedd3061559a7 (patch) | |
tree | 2262e9acb4d3c3798a6f4083e349f05d24f23dd3 | |
parent | afc530ea411e18223b0323d7e11aa0fab9289d65 (diff) | |
download | dexon-d6a7332993cf32960ef94947341cedd3061559a7.tar.gz dexon-d6a7332993cf32960ef94947341cedd3061559a7.tar.zst dexon-d6a7332993cf32960ef94947341cedd3061559a7.zip |
accounts: fix uses of sync.RWMutex
RWMutexes must be write-locked when writing in order
to actually protect the writes.
-rw-r--r-- | accounts/account_manager.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go index f87cce65f..c0f2953bd 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -111,9 +111,9 @@ func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) ( if err != nil { return nil, err } - am.mutex.RLock() + am.mutex.Lock() am.unlockedKeys[string(a.Address)] = *key - am.mutex.RUnlock() + am.mutex.Unlock() go unlockLater(am, a.Address) signature, err = crypto.Sign(toSign, key.PrivateKey) return signature, err @@ -147,8 +147,10 @@ func unlockLater(am *AccountManager, addr []byte) { select { case <-time.After(am.unlockTime): } - am.mutex.RLock() + am.mutex.Lock() // TODO: how do we know the key is actually gone from memory? delete(am.unlockedKeys, string(addr)) - am.mutex.RUnlock() + am.mutex.Unlock() +} + } |