Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes #1482, removed unsafe double RLock in (p *pool) SelectAP
Browse files Browse the repository at this point in the history
Removed double RLock in (p *pool) Eligible()

Replaced lock for reading with lock for writing (RLock/RUnlock -> Lock/Unlock) in (p *pool) IncRestartCount
  • Loading branch information
katarzyna-z committed Feb 24, 2017
1 parent 85079bc commit 70d5b5e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions control/strategy/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 70d5b5e

Please sign in to comment.