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

Fixes #1482, removed unsafe double RLock #1525

Merged
merged 1 commit into from
Feb 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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