Browse code

Fix race in setting plugin refcounts.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>
(cherry picked from commit 4c088d1e2ebfcc384a365734017988f4fd1c4605)
Signed-off-by: Victor Vieux <vieux@docker.com>

Anusha Ragunathan authored on 2016/12/10 02:34:30
Showing 2 changed files
... ...
@@ -174,7 +174,7 @@ func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlug
174 174
 		}
175 175
 		p, err = ps.GetByName(fullName)
176 176
 		if err == nil {
177
-			p.SetRefCount(mode + p.GetRefCount())
177
+			p.AddRefCount(mode)
178 178
 			if p.IsEnabled() {
179 179
 				return p.FilterByCap(capability)
180 180
 			}
... ...
@@ -286,12 +286,12 @@ func (p *Plugin) GetRefCount() int {
286 286
 	return p.refCount
287 287
 }
288 288
 
289
-// SetRefCount sets the reference count.
290
-func (p *Plugin) SetRefCount(count int) {
289
+// AddRefCount adds to reference count.
290
+func (p *Plugin) AddRefCount(count int) {
291 291
 	p.mu.Lock()
292 292
 	defer p.mu.Unlock()
293 293
 
294
-	p.refCount = count
294
+	p.refCount += count
295 295
 }
296 296
 
297 297
 // InitSpec creates an OCI spec from the plugin's config.