mirror of https://github.com/k3s-io/k3s
Merge pull request #26758 from mqliang/lookupcache-threadsafe
Automatic merge from submit-queue bugfix:lookupcache's Get method can not be called concurrently ref https://github.com/kubernetes/kubernetes/issues/26376 @lavalamp @therc @mikedanesepull/6/head
commit
a00dbea133
|
@ -72,8 +72,10 @@ func (c *MatchingCache) Add(labelObj objectWithMeta, selectorObj objectWithMeta)
|
|||
// we need check in the external request to ensure the cache data is not dirty.
|
||||
func (c *MatchingCache) GetMatchingObject(labelObj objectWithMeta) (controller interface{}, exists bool) {
|
||||
key := keyFunc(labelObj)
|
||||
c.mutex.RLock()
|
||||
defer c.mutex.RUnlock()
|
||||
// NOTE: we use Lock() instead of RLock() here because lru's Get() method also modifies state(
|
||||
// it need update the least recently usage information). So we can not call it concurrently.
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
return c.cache.Get(key)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue