From 70d5b5ecd211d7bf879f86b9c655eada49cb3179 Mon Sep 17 00:00:00 2001 From: katarzyna-z Date: Thu, 16 Feb 2017 15:05:42 +0100 Subject: [PATCH] Fixes #1482, removed unsafe double RLock in (p *pool) SelectAP Removed double RLock in (p *pool) Eligible() Replaced lock for reading with lock for writing (RLock/RUnlock -> Lock/Unlock) in (p *pool) IncRestartCount --- control/strategy/pool.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/control/strategy/pool.go b/control/strategy/pool.go index 01174a41e..05a6c3d9d 100644 --- a/control/strategy/pool.go +++ b/control/strategy/pool.go @@ -171,8 +171,8 @@ func (p *pool) RestartCount() int { } func (p *pool) IncRestartCount() { - p.RLock() - defer p.RUnlock() + p.Lock() + defer p.Unlock() p.restartCount++ } @@ -261,12 +261,12 @@ func (p *pool) Eligible() bool { // optimization: don't even bother with concurrency // count if we have already reached pool max - if p.Count() >= p.max { + if len(p.plugins) >= p.max { return false } // Check if pool is eligible and number of plugins is less than maximum allowed - if p.SubscriptionCount() > p.concurrencyCount*p.Count() { + if len(p.subs) > p.concurrencyCount*len(p.plugins) { return true } @@ -361,10 +361,8 @@ func (p *pool) SubscriptionCount() int { } // SelectAP selects an available plugin from the pool +// the method is not thread safe, it should be protected outside of the body func (p *pool) SelectAP(taskID string, config map[string]ctypes.ConfigValue) (AvailablePlugin, serror.SnapError) { - p.RLock() - defer p.RUnlock() - aps := p.plugins.Values() var id string