From 955998db8382231fcb359439d8aa4962623baa02 Mon Sep 17 00:00:00 2001 From: Anusha Ragunathan Date: Fri, 9 Dec 2016 09:34:30 -0800 Subject: [PATCH] Fix race in setting plugin refcounts. Signed-off-by: Anusha Ragunathan Upstream-commit: 4c088d1e2ebfcc384a365734017988f4fd1c4605 Component: engine --- components/engine/plugin/store/store.go | 2 +- components/engine/plugin/v2/plugin.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/engine/plugin/store/store.go b/components/engine/plugin/store/store.go index f456f97033..7b67fa9cd3 100644 --- a/components/engine/plugin/store/store.go +++ b/components/engine/plugin/store/store.go @@ -174,7 +174,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) } diff --git a/components/engine/plugin/v2/plugin.go b/components/engine/plugin/v2/plugin.go index 4046bf7dbe..04b64538b9 100644 --- a/components/engine/plugin/v2/plugin.go +++ b/components/engine/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.