mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fix(azure::cache): TimedCache.Getter should be called once on the same key
If a key have't been saved in TimedCache, and there are multiple goroutines getting this key, TimedCache.Getter might be invoked multiple times because the entry is overwritten in TimedCache.getInternal. Signed-off-by: knight42 <anonymousknight96@gmail.com>
This commit is contained in:
parent
90ddd5f721
commit
2b1395a88a
@ -103,6 +103,15 @@ func (t *TimedCache) getInternal(key string) (*AzureCacheEntry, error) {
|
||||
t.Lock.Lock()
|
||||
defer t.Lock.Unlock()
|
||||
|
||||
// Another goroutine might have written the same key.
|
||||
entry, exists, err = t.Store.GetByKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if exists {
|
||||
return entry.(*AzureCacheEntry), nil
|
||||
}
|
||||
|
||||
// Still not found, add new entry with nil data.
|
||||
// Note the data will be filled later by getter.
|
||||
newEntry := &AzureCacheEntry{
|
||||
|
Loading…
Reference in New Issue
Block a user