Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential race condition in cachedKeyService #1194

Closed
rhonnava opened this issue Jul 16, 2017 · 1 comment
Closed

Potential race condition in cachedKeyService #1194

rhonnava opened this issue Jul 16, 2017 · 1 comment

Comments

@rhonnava
Copy link
Contributor

rhonnava commented Jul 16, 2017

The implementation of cachedKeyService in signer/keydbstore/cachedcryptoservice.go uses a sync.Mutex{} to synchronize write access to the cache map. However, reading from the map in GetPrivateKey in this line: cachedKeyEntry, ok := s.cachedKeys[keyID] is not protected using a read lock. So, there can be a race condition when the map is being updated at the same time when it is being read.

I would suggest using sync.RWMutex instead of sync.Mutex and using a read lock around access:

s.lock.RLock()
cachedKeyEntry, ok := s.cachedKeys[keyID]
s.lock.RUnlock()

I can submit a pull request if you are okay with this.

May also be worth considering sync.map: golang/go#18177 when Notary is on the golang version that supports it.

@cyli
Copy link
Contributor

cyli commented Jul 20, 2017

@rhonnava Thanks for pointing this out - sure a PR would be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants