From d2de61c650dbb1d3e0f2a2f4257f1c11cfd6b69c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 1 Jun 2016 10:05:45 -0400 Subject: [PATCH] Revert "Use mutexes directly, not pointers, in the token store mutex map" This reverts commit 29f8d2ad75c2767e21b406d32c7a7a9dc6f9c3f2. --- vault/token_store.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vault/token_store.go b/vault/token_store.go index 261dce9c5..a0071e27b 100644 --- a/vault/token_store.go +++ b/vault/token_store.go @@ -64,7 +64,7 @@ type TokenStore struct { policyLookupFunc func(string) (*Policy, error) - tokenLocks map[string]sync.RWMutex + tokenLocks map[string]*sync.RWMutex } // NewTokenStore is used to construct a token store that is @@ -91,12 +91,12 @@ func NewTokenStore(c *Core, config *logical.BackendConfig) (*TokenStore, error) } t.salt = salt - t.tokenLocks = map[string]sync.RWMutex{} + t.tokenLocks = map[string]*sync.RWMutex{} for i := int64(0); i < 256; i++ { t.tokenLocks[fmt.Sprintf("%2x", - strconv.FormatInt(i, 16))] = sync.RWMutex{} + strconv.FormatInt(i, 16))] = &sync.RWMutex{} } - t.tokenLocks["custom"] = sync.RWMutex{} + t.tokenLocks["custom"] = &sync.RWMutex{} // Setup the framework endpoints t.Backend = &framework.Backend{ @@ -569,14 +569,14 @@ func (ts *TokenStore) storeCommon(entry *TokenEntry, writeSecondary bool) error return nil } -func (ts *TokenStore) getTokenLock(id string) sync.RWMutex { +func (ts *TokenStore) getTokenLock(id string) *sync.RWMutex { // Find our multilevel lock, or fall back to global - var lock sync.RWMutex + var lock *sync.RWMutex var ok bool if len(id) >= 2 { lock, ok = ts.tokenLocks[id[0:2]] } - if !ok { + if !ok || lock == nil { // Fall back for custom token IDs lock = ts.tokenLocks["custom"] }