Skip to content

Commit 2b1395a

Browse files
committed
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 <[email protected]>
1 parent 90ddd5f commit 2b1395a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/cache/azure_cache.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ func (t *TimedCache) getInternal(key string) (*AzureCacheEntry, error) {
103103
t.Lock.Lock()
104104
defer t.Lock.Unlock()
105105

106+
// Another goroutine might have written the same key.
107+
entry, exists, err = t.Store.GetByKey(key)
108+
if err != nil {
109+
return nil, err
110+
}
111+
if exists {
112+
return entry.(*AzureCacheEntry), nil
113+
}
114+
106115
// Still not found, add new entry with nil data.
107116
// Note the data will be filled later by getter.
108117
newEntry := &AzureCacheEntry{

0 commit comments

Comments
 (0)