mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
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 @mikedanese
This commit is contained in:
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.
|
// 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) {
|
func (c *MatchingCache) GetMatchingObject(labelObj objectWithMeta) (controller interface{}, exists bool) {
|
||||||
key := keyFunc(labelObj)
|
key := keyFunc(labelObj)
|
||||||
c.mutex.RLock()
|
// NOTE: we use Lock() instead of RLock() here because lru's Get() method also modifies state(
|
||||||
defer c.mutex.RUnlock()
|
// 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)
|
return c.cache.Get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user