Explorar o código

Merge pull request #29281 from anusha-ragunathan/fix_race

Fix race in setting plugin refcounts.
Anusha Ragunathan %!s(int64=8) %!d(string=hai) anos
pai
achega
86a0de7fa9
Modificáronse 2 ficheiros con 4 adicións e 4 borrados
  1. 1 1
      plugin/store/store.go
  2. 3 3
      plugin/v2/plugin.go

+ 1 - 1
plugin/store/store.go

@@ -181,7 +181,7 @@ func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlug
 		}
 		p, err = ps.GetByName(fullName)
 		if err == nil {
-			p.SetRefCount(mode + p.GetRefCount())
+			p.AddRefCount(mode)
 			if p.IsEnabled() {
 				return p.FilterByCap(capability)
 			}

+ 3 - 3
plugin/v2/plugin.go

@@ -278,12 +278,12 @@ func (p *Plugin) GetRefCount() int {
 	return p.refCount
 }
 
-// SetRefCount sets the reference count.
-func (p *Plugin) SetRefCount(count int) {
+// AddRefCount adds to reference count.
+func (p *Plugin) AddRefCount(count int) {
 	p.mu.Lock()
 	defer p.mu.Unlock()
 
-	p.refCount = count
+	p.refCount += count
 }
 
 // InitSpec creates an OCI spec from the plugin's config.